I've setup my Raspberry Pi 2 Model B v1.1 with Node.js v8.7 and installed the rpi-gpio module.
I used Node shell (REPL) to test the module, and it worked like a charm. But when I put the same 3 lines of code in app.js and try a node app.js I get the following error. Code added below for reference.
Error:
/home/pi/PiClient/node_modules/rpi-gpio/rpi-gpio.js:358
return currentPins[channel] + '';
^
TypeError: Cannot read property '7' of undefined
at getPinRpi (/home/pi/PiClient/node_modules/rpi-gpio/rpi-gpio.js:358:27)
at Gpio.read.input (/home/pi/PiClient/node_modules/rpi-gpio/rpi-gpio.js:266:19)
at Object.<anonymous> (/home/pi/PiClient/test.js:5:6)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:187:16)
Code:
var gpio = require('rpi-gpio');
gpio.(7, gpio.DIR_IN);
gpio.read(7, function (err, val) {
console.log(err, val);
});