Haven
Haven

Reputation: 7966

node.js server on raspberry pi

I am new to node.js and Raspberry pi, I just followed the tutorial in http://joshondesign.com/2013/10/23/noderpi

now npm -version and node -v shows well.

then I put the server.js file in home/pi/app directory

every time I run sudo node /home/pi/app/server.js or move to the app directory run sudo node server.js

It comes out an error, which is:

sudo : node: command not found?

How to fix that? And is there any method to set the server start automatically every time I boot the Pi?

Upvotes: 0

Views: 2517

Answers (2)

Erik E. Lorenz
Erik E. Lorenz

Reputation: 385

Try

sudo $(which node) /home/pi/app/server

This way, you are searching the executable file location before running sudo, since your user's PATH is not searchable in a sudo environment.

About autorun, you should search Google for sysvinit or systemd, depending on your operating system. They are able to start daemons as root after boot.

Upvotes: 2

wesolyromek
wesolyromek

Reputation: 650

You may want to check this thread: On EC2: sudo node command not found, but node without sudo is ok This should help:

sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf

Upvotes: 0

Related Questions