[SOLVED] Cannot find module blynk-library


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:

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);

The test script blynk.js works very well.

Can anyone help me. Thanks

Ok i write the complete path to blynk-library in the require syntax. It works.

1 Like

Try using /usr/local/lib/node_modules/blynk-library instead. It works for me.

1 Like

Actually you should export NODE_PATH…

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.

does this folder contain blynk-library ?

I was not able to check the folder until today. Yes it does contain the blink-library.



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? :neutral_face:

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.

1 Like

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

sudo NODE_PATH=/usr/local/lib/node_modules node ./blynk-test.js

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).


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

sudo NODE_PATH=/usr/local/lib/node_modules node ./blynk-sensor-test.js

, 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?

Anyone have any idea what could be causing this?

@BigP0P5 what command are you using to run your script?

You just need to ensure you use the full path.

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 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);

If you have set up node and if you store the script with the other scripts in blynk-library and the script is names blynk-test.js it should be:

node /usr/local/lib/node_modules/blynk-library/blynk-test.js

Play around with this and let me know if you get it going consistently.

Everything is up and working fine now, except for crontab.

On to possibly start a new thread.

You saying if you move your file to


it doesn’t run with:

node /usr/local/lib/node_modules/blynk-library/blynksample.js

or it doesn’t run from crontab, or both?

1 Like

@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.

export NODE_PATH=/usr/local/lib/node_modules

@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

1 step forward 2 steps back.

@BigP0P5 node /usr/local/lib/node_modules/blynk-library/blynk.js token

Doesn’t seem to do anything.
Just brings back the prompt.