Error: Cannot find module 'bonescript'

543 views
Skip to first unread message

Maurice H.

unread,
Dec 18, 2015, 4:38:53 PM12/18/15
to BeagleBoard

I have this simple script that I want to execute at boot time.

The script:
root@bbone:~# cat boneboot/ledsoff.js
var b=require('bonescript');


b
.pinMode('USR0', 'out');
b
.pinMode('USR1', 'out');
b
.pinMode('USR2', 'out');
b
.pinMode('USR3', 'out');


b
.digitalWrite('USR0', 0);
b
.digitalWrite('USR1', 0);
b
.digitalWrite('USR2', 0);
b
.digitalWrite('USR3', 0);

To run it at boot I've created a file in /etc/cron.d which looks like this:
root@bbone:~# cat /etc/cron.d/boneboot
# m h dom mon dow user  command
@reboot   root    sleep 120 && /usr/bin/nodejs /root/boneboot/ledsoff.js 2>&1 | logger -p info -t ledsoff

Unfortunately, when I reboot the BBB the code is not executed succesfully as shown by the log:
root@bbone:~# cat /var/log/syslog
Dec 18 21:54:49 bbone ledsoff:
Dec 18 21:54:49 bbone ledsoff: module.js:340
Dec 18 21:54:49 bbone ledsoff:     throw err;
Dec 18 21:54:49 bbone ledsoff:           ^
Dec 18 21:54:50 bbone ledsoff: Error: Cannot find module 'bonescript'
Dec 18 21:54:50 bbone ledsoff:     at Function.Module._resolveFilename (module.js:338:15)
Dec 18 21:54:50 bbone ledsoff:     at Function.Module._load (module.js:280:25)
Dec 18 21:54:50 bbone ledsoff:     at Module.require (module.js:364:17)
Dec 18 21:54:50 bbone ledsoff:     at require (module.js:380:17)
Dec 18 21:54:50 bbone ledsoff:     at Object.<anonymous> (/root/boneboot/ledsoff.js:1:69)
Dec 18 21:54:50 bbone ledsoff:     at Module._compile (module.js:456:26)
Dec 18 21:54:50 bbone ledsoff:     at Object.Module._extensions..js (module.js:474:10)
Dec 18 21:54:50 bbone ledsoff:     at Module.load (module.js:356:32)
Dec 18 21:54:50 bbone ledsoff:     at Function.Module._load (module.js:312:12)
Dec 18 21:54:50 bbone ledsoff:     at Function.Module.runMain (module.js:497:10)

However, when I logged in as root, the code executes normally.

Any suggestions on how to proceed?



Maurice H.

unread,
Dec 19, 2015, 8:33:40 AM12/19/15
to BeagleBoard
I've solved this by adding a line to the cron job that sets the environment variable NODE_PATH.

NODE_PATH=/usr/local/lib/node_modules
# m h dom mon dow user  command
@reboot   root    sleep 120 && /usr/bin/nodejs /root/boneboot/ledsoff.js 2>&1 | logger -p info -t ledsoff
Reply all
Reply to author
Forward
0 new messages