Reputation:
I have installed serialport using npm, but why its failing to connect?
$ ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbserial-AI0255BX
$ cat /var/tmp/test.js
var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty.usbserial-AI0255BX', {
baudRate: 57600
});
$ node /var/tmp/test.js
module.js:471
throw err;
^
Error: Cannot find module 'serialport'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/private/var/tmp/test.js:1:80)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Upvotes: 0
Views: 340
Reputation: 108
Nodejs search package.json in the same folder as the script. If it does not found it search in the parent folder etc...
I see in your pastbin that you have install the node module in your home, so package.json is unattainable for Node.
You can try this :
The -g (global) option permit to use the bin no matter where you are.
Or :
Upvotes: 1