i would like to start a script for raspberry pi 2. I have installed blink-library via npm install.
But if i start the script i get the following error message:
module.js:338
throw err;
^
Error: Cannot find module 'blynk-library'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/pi/BlynkScripts/blynk-start-Kodi.js:3:13)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
My Code is:
#!/usr/bin/env node
var Blynk = require('blynk-library');
var sys = require('sys')
var exec = require('child_process').exec;
var AUTH = '5203b4d7c39444089981051b926c62e6';
var blynk = new Blynk.Blynk(AUTH);
var v9 = new blynk.VirtualPin(9);
v9.on('write', function(param) {
console.log('V1:', param);
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("kodi", puts);
});
I am having the same issue as shinig01 above. I can run the blynk.js and make a LED turn on and off from my phone. I tried the export NODE_PATH=/usr/local/lib/node_modules and still get the above error.
I attempted to follow @vshymanskyy 's Blynk + JavaScript Instructable and got the "Error: Cannot find module blynk-library"when trying to run blynk-test1.js. I guess I should look into the Arduino’s until Blynk gets some Pi’s?
I could not make use of any of the above remedies as well. Perhaps I didn’t understand them clearly but I attempted a few stabs and nothing changed.
So I decided I was going to figure this out, one way or another.
After looking around on the file directory, I noticed two major file mains. One was /pi and the other was just /. It didn’t take long afterwards to find under the / (main) the /usr/local/lib/node_modules section. Up until then, I could not find it. That’s just apart of playing with something that you’ve had for less than a week. I then worked on finding the proper format of entering the command and eventually found that
was the key to properly running the command (which later allowed me to experiment with the display widget showing seconds and the slider showing values).
Currently,
export NODE_PATH=/usr/local/lib/node_modules
does not do it for me. Without sudo, I don’t think any of it’s possible. Also, I don’t think including export is necessary in this function. The script
, from the RPi + DHT11 demonstration, is spot on though and is what inevitably led me to overcoming this obstacle. Thank you @vshymanskyy for providing the demonstrations - they were very helpful resources.
I am also having this issue. I will run my script and everything works out fine. And after a couple reboots, I will get the Error: Cannot find module ‘blynk-library’.
I run the command NODE_PATH=/usr/local/lib/node_modules and everything is back to normal?
I am trying to get crontab to work for me by running at startup:
I execute usr/bin/nodejs home/pi/Blynk_Scripts/blynksample.js from the command line after reboot and get the above error and remedy it s previously mentioned.
This is what blynksample.js contains:
var Blynk = require('blynk-library');
var AUTH = 'YOUR_AUTH_TOKEN';
var blynk = new Blynk.Blynk(AUTH);
var v1 = new blynk.VirtualPin(1);
var v9 = new blynk.VirtualPin(9);
v1.on('write', function(param) {
console.log('V1:', param[0]);
});
v9.on('read', function() {
v9.write(new Date().getSeconds());
var term = new blynk.WidgetTerminal(3);
term.on('write', function(data) {
term.write('You wrote:' + data + '\n');
blynk.notify("HAHA! " + data);
});
@vshymanskyy can you please confirm that the following command is a one time requirement that should set the node path permanently, as it doesn’t seem to work for some Blynkers.
@BigP0P5 it looks like export only retains the variables during the current session AND possibly only within the current shell if it’s included in a bash script.
So that is probably why you are struggling to run the js files when the Pi reboots.
Hence the use of the forever-service etc.
I don’t know what you have different to me as it all runs fine on my Pi after a reboot. The only difference I can think is that I have my app.js in the /home/pi directory whereas you have yours way down in the /usr/local/lib/node_modules/blynk-library directory.
Provided the full paths are included in all the require statements it should work.
You could remove the app.js service from forever-service (see GitHub for syntax), create app.js in /home/pi and create the forever-service again.
I am now a step further back after reinstalling.
After I enter export NODE_PATH=/usr/local/lib/node_modules
Then I go to run the blynk.js and I get bash: blynk.js: command not found
I tried to run the full path: /usr/local/lib/node_modules/blynk-library/blynk.js daf551e6443a4347a04a3e6dddda0a79
bash: /usr/local/lib/node_modules/blynk-library/blynk.js: Permission denied