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

pkyeck picture pkyeck · Aug 11, 2011 · Viewed 61.8k times · Source

i got the daemon working alright with these instructions: http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/

but because this starts the application in DEVELOPMENT mode, the log file gets spammed with socket.io debug logs.

i tried setting the NODE_ENV to production in the upstart-conf-file but had no success.

script
    export HOME="/root"
    export NODE_ENV=production

    exec /usr/local/bin/node /where/yourprogram.js >> /var/log/node.log 2>&1
end script

didn't work.

Answer

Yuval picture Yuval · Aug 19, 2011

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.