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.

1
  • Create a bash script? After all you're just writing bash. Or create two different start actions. Commented Jul 15, 2014 at 3:39

1 Answer 1

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);
}
Sign up to request clarification or add additional context in comments.

2 Comments

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');
Do it in your server.js via stackoverflow.com/questions/4870328/… You should set env variables on your system and check it in your programm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.