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.
-
Create a bash script? After all you're just writing bash. Or create two different start actions.elclanrs– elclanrs2014-07-15 03:39:44 +00:00Commented Jul 15, 2014 at 3:39
Add a comment
|
1 Answer
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);
}
2 Comments
user2066880
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');medokin
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.