Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 567
Philipp Kyeck Avatar asked Aug 11 '11 08:08

Philipp Kyeck


People also ask

What is NODE_ENV in node JS?

NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).

What are the NODE_ENV values?

Introduction: NODE_ENV variables are environment variables that are made popularized by the express framework. The value of this type of variable can be set dynamically depending on the environment(i.e., development/production) the program is running on.


2 Answers

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.

like image 80
Yuval Avatar answered Sep 27 '22 19:09

Yuval


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 <[email protected]>"  start on filesystem and started networking respawn console log chdir /opt/your_app setuid your_app_user setgid your_app_user env PATH=./node_modules/.bin:./node/bin:/usr/bin env NODE_ENV=production exec app/server.js 
like image 20
Peter Lyons Avatar answered Sep 27 '22 20:09

Peter Lyons