Raspberry Pi node.js physical button

Hello, I am making a program when you push a physical button, you get a notification on your smartphone. I wrote this program:

var Blynk = require(‘/usr/local/lib/node_modules/blynk-library’);
var Gpio = require(‘onoff’).Gpio;
var AUTH = ‘b6216e4b56964600ba05627ddc003dbf’;

var button = new Gpio(18, ‘in’);

var blynk = new Blynk.Blynk(AUTH);

var v6 = new blynk.VirtualPin(6);

button.on(‘write’, function(param) {
if (param == 1) {blynk.notify(“Deksel open”);}
});

but when I try it it gives me this error:


/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/

Give Blynk a Github star! => GitHub - vshymanskyy/blynk-library-js: Blynk library for JS. Works with Browsers, Node.js, Espruino.

OnOff mode
Connecting to: blynk-cloud.com 9443
/home/pi/test-project/program.js:13
button.on(‘write’, function(param) {
^

TypeError: button.on is not a function
at Object. (/home/pi/test-project/program.js:13:8)
at Module._compile (module.js:652:30)
at Object.Module._extensions…js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

Is there someone that nows the correct way to program with Gpio pins?

There are examples in the GitHub library and I have a few examples in the link below that show how to setup the variables and buttons, etc… I haven’t tried Notifications and do not know if they even work with Blynk NodeJS

I already tried to send a notification in node.js when i push a virtual button and that program was working but it is not very clear how I have to do it with the Gpio input. Because i saw a video on yt from blynk and there to use other ‘onoff’ instead of ‘pigpio’ in ur example.

I don’t use onoff, so can’t tell you anything about it. I find pigpio more useful with it’s plentiful control options.

But you can pick whatever GPIO library you want and simply Google for it’s particular set up directions.

https://www.npmjs.com/search?q=gpio