BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

JS Cannot find module 'blynk-library'


#1

Hi friends. the problem with the below code with JS script. any way to fix ?
thanks

the error:

module.js:549
    throw err;
    ^

Error: Cannot find module 'blynk-library'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/test.js:1:75)
    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)

the JS code

var Blynk = require('blynk-library');

var AUTH = '90d28c96e66f49868cdcb9868c760be0';
var blynk = new Blynk.Blynk(AUTH, options = { connector : new Blynk.TcpClient( options = { addr:"10.5.50.18", port:8080 } ) });

var exec = require('child_process').exec, child;
var v0 = new blynk.VirtualPin(0);
var v1 = new blynk.VirtualPin(1);
var v2 = new blynk.VirtualPin(2);
var v3 = new blynk.VirtualPin(3);
var slider = new blynk.VirtualPin(4);
var writeVal = '';

//volume control using slider
slider.on('write', function(param) {
	child = exec('amixer set PCM ' + param[0] + '%',
		function (error, stdout, stderr) {
        console.log('stdout: ' + stdout);
        console.log('stderr: ' + stderr);
        if (error !== null) {
             console.log('exec error: ' + error);
        }
    });
});

//turn on squeezelite turn off others
v1.on('write', function(param) {
	if (param[0] == '1') {
		child = exec('sudo /etc/init.d/squeezelite start',
		    function (error, stdout, stderr) {
		        console.log('stdout: ' + stdout);
		        console.log('stderr: ' + stderr);
		        if (error !== null) {
		             console.log('exec error: ' + error);
		        }
		    });
		writeVal = 'squeezelite ON'; 
	}
	else if (param[0] == '0') {
		child = exec('sudo /etc/init.d/squeezelite stop',
	    	function (error, stdout, stderr) {
		        console.log('stdout: ' + stdout);
		        console.log('stderr: ' + stderr);
	        	if (error !== null) {
	            	console.log('exec error: ' + error);
        		}
    		});
		writeVal = 'squeezelite OFF';
	}
});


v2.on('write', function(param) {
	if (param[0] == '1') {
		child = exec('sudo systemctl start shairport-sync',
		    function (error, stdout, stderr) {
		        console.log('stdout: ' + stdout);
		        console.log('stderr: ' + stderr);
		        if (error !== null) {
		             console.log('exec error: ' + error);
		        }
		    });
		writeVal = 'shairport ON'; 
	}
	else if (param[0] == '0') {
		child = exec('sudo systemctl stop shairport-sync',
	    	function (error, stdout, stderr) {
		        console.log('stdout: ' + stdout);
		        console.log('stderr: ' + stderr);
	        	if (error !== null) {
	            	console.log('exec error: ' + error);
        		}
    		});
		writeVal = 'shairport OFF';
	}
});

v3.on('write', function(param) {
	if (param[0] == '1') {
		child = exec('ecasound -C -q -B:rt -b:1024 -f:16,2,48000 -i:alsahw,1,0',
		    function (error, stdout, stderr) {
		        console.log('stdout: ' + stdout);
		        console.log('stderr: ' + stderr);
		        if (error !== null) {
		             console.log('exec error: ' + error);
		        }
		    });
		writeVal = 'analog ON'; 
	}
	else if (param[0] == '0') {
		child = exec('sudo killall -15 ecasound',
	    	function (error, stdout, stderr) {
		        console.log('stdout: ' + stdout);
		        console.log('stderr: ' + stderr);
	        	if (error !== null) {
	            	console.log('exec error: ' + error);
        		}
    		});
		writeVal = 'analog OFF';
	}
});


v0.on('read', function() {
  v0.write(writeVal);
});

but the library working:

pi@raspberrypi:~ $ blynk-client a6d6a08f382a4d60bd348707bfdee103

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/

  Give Blynk a Github star! => https://github.com/vshymanskyy/blynk-library-js

Connecting to: blynk-cloud.com 8441
SSL authorization...
Connected
Authorized
Blynk ready.

#2

the problem solved by this tutorial: http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/raspberry-pi/how-to-install-nodejs-library-on-linux