setting NODE_ENV for node.js + expressjs application as a daemon under ubuntu setting NODE_ENV for node.js + expressjs application as a daemon under ubuntu linux linux

setting NODE_ENV for node.js + expressjs application as a daemon under ubuntu


Try

exec NODE_ENV=production /usr/local/bin/node /where/yourprogram.js >> /var/log/node.log 2>&1

In my setup I'm sudoing as a lesser user, so it's

exec sudo -u some-user NODE_ENV=production /usr/local/bin/node /where/yourprogram.js >> /var/log/node.log 2>&1

and since it's spawning off another user it probably has another environment. I'm a newbie here, but it works for me.


Here's a simpler upstart script you can use. Upstart now supports everything you need to do directly without script sections or too much embedded shell syntax. This includes environment variables (env), working directory (chdir), user/group (setuid, setgid), log handling (console log), etc. Your log files will be handled and rotated into /var/log/upstart/your_app.log

description "start and stop the example express.js/node.js server"author "John Doe <jd@example.com>"start on filesystem and started networkingrespawnconsole logchdir /opt/your_appsetuid your_app_usersetgid your_app_userenv PATH=./node_modules/.bin:./node/bin:/usr/binenv NODE_ENV=productionexec app/server.js


If you are using node.js in production, I recommend you use forever.js to daemonize your programhttps://github.com/nodejitsu/forever

Install using npm: [sudo] npm install forever -g

export NODE_ENV=production and run forever start app.js You can also specify where to put error and stdout logs.