# I can't stop NR (I can only kill process)

**URL:** <https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853>\
**Category:** General\
**Created:** [23 April 2023 17:36 UTC](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853 "2023-04-23T17:36:42Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [25 April 2023 08:07 UTC](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853/22 "2023-04-25T08:07:33Z")

</div>

Hi, yes I could advice myself what he wrote, anyway the module works, it just hang NR from quit. It's highly probable that a little correction will fix the problem, I'm asking here if someone kindly can advice whrere the problem is. Unfortunately there aren't other nodes that can read `cat /dev/input/event0  
I post the code here:  
JSON:

```auto
{
  "name": "node-red-contrib-dev-input",
  "version": "0.0.1",
  "description": "Basic Node-Red node for use in /dev/input/event reading.",
  "main": "dev-input.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/MattGyver/node-red-contrib-dev-input.git"
  },
  "keywords": [
    "node-red",
    "input",
    "event",
    "hid"
  ],
  "node-red": {
    "nodes": {
      "devinput": "dev-input.js"
    }
  },
  "author": "Mattias Nord",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/MattGyver/node-red-contrib-dev-input/issues"
  },
  "homepage": "https://github.com/MattGyver/node-red-contrib-dev-input#readme"
}

```

HTML:

```auto
<script type="text/javascript">
    RED.nodes.registerType('dev-input',{
        category: 'input',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
            device: {valie:""}
        },
        inputs:0,
        outputs:1,
        icon: "file.png",
        label: function() {
            return this.name||"dev-input";
        }
    });
</script>

<script type="text/x-red" data-template-name="dev-input">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-row">
        <label for="node-input-device"><i class="icon-tag"></i> Device</label>
        <input type="text" id="node-input-device" placeholder="/dev/input/event0">
    </div>
</script>

<script type="text/x-red" data-help-name="dev-input">
    <p>A simple node that reads specified /dev/input event and forward the event data in msg.payload.</p>
</script>

```

JS:

```auto
module.exports = function(RED) {

  var msg = { topic:"dev-input" }

  function parseBuffer( buffer ) {
    var eventObject = {};

    eventObject.code = buffer[12];

    return eventObject;
  }

  function DevInput(config) {
    RED.nodes.createNode(this,config);
    var node = this;

    if (config.device != undefined) {
      var FS = require('fs');

      if (!FS.existsSync(''+config.device)) {
        throw "Can't find device.";
      }

      FS.createReadStream(''+config.device).on('data', function( buffer ) {
        msg.payload = parseBuffer(buffer)
        node.send(msg);
      });
    }

  }
  RED.nodes.registerType("dev-input",DevInput);
}

```

Thank you a lot

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [25 April 2023 17:04 UTC](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853/23 "2023-04-25T17:04:16Z")

</div>

is the code

```auto
      FS.createReadStream(''+config.device).on('data', function( buffer ) {
        msg.payload = parseBuffer(buffer)
        node.send(msg);

```

openng the file but there is nothing that closes it when NR is switching off? Can it be that the reason it hangs?  
Thank you

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 April 2023 06:23 UTC](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853/24 "2023-04-26T06:23:56Z")

</div>

Certainly the on close function should release any resources acquired.  
[https://nodered.org/docs/creating-nodes/node-js#closing-the-node](https://nodered.org/docs/creating-nodes/node-js#closing-the-node)

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [27 April 2023 17:54 UTC](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853/25 "2023-04-27T17:54:06Z")

</div>

Mate, thanks for keep me helping on this post,  
I've understand it but I have no clue how to.. my javascript level is low and I?m able onoy to write functions with checks and for cycles (( can you kindly help me to insert this code on quit event?  
May I eventaully open another topic asking specific help to users how to do this? Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 June 2023 17:54 UTC](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853/26 "2023-06-26T17:54:39Z")

</div>

Closed on 26 June 2023 17:54 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/i-cant-stop-nr-i-can-only-kill-process/77853.md?page=1)
