0

Is there a way to configure package.json to run a different npm start script based on context? For example, I would like to run DEBUG=http nodemon app.js when I am developing. But, I would like to run node app.js on production.

user2066880
  • 4,825
  • 9
  • 38
  • 64

1 Answers1

1

Create a new file (e.g. server.js) and insert your app.js content.

Use this code sample inside of app.js

var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }


var isDev = // Check if on dev machine

if(isDev){
  exec("DEBUG=http nodemon server.js", puts);
} else {
  exec("node server.js", puts);
}
medokin
  • 610
  • 9
  • 21
  • Thanks, I'd like to also add that with express, the default environment mode is "development". This can be changed via `app.set('env', 'production');` – user2066880 Jul 16 '14 at 00:44
  • Do it in your server.js via http://stackoverflow.com/questions/4870328/how-to-read-environment-variable-in-node-js You should set env variables on your system and check it in your programm. – medokin Jul 16 '14 at 10:05