创建启动脚本

sudo nano nodejs.sh
#!/bin/bash 
NODE=/opt/node/bin/node 
SERVER_JS_FILE=/home/pi/git/pi-camera/app.js 
USER=pi 
OUT=/home/pi/nodejs.log 
case "$1" in 
start) 
    echo "starting node: $NODE $SERVER_JS_FILE" 
    sudo -u $USER $NODE $SERVER_JS_FILE > $OUT 2>$OUT & 
    ;; 
stop) 
    killall $NODE 
    ;; 
*) 
    echo "usage: $0 (start|stop)" 
esac 
exit 0

加入启动项

sudo chmod 755 nodejs.sh

sudo cp nodejs.sh /etc/init.d

sudo update-rc.d nodejs.sh defaults

启动

sudo /etc/init.d/nodejs.sh start