U
U
Umid2017-01-24 09:45:27
Node.js
Umid, 2017-01-24 09:45:27

What is the correct way to configure npm start script with NODE_ENV=development tag?

Good afternoon.
How can I properly configure the npm start script so that it says NODE_ENV=development?
Tried to do so. Outputs an error.
"start": "NODE_ENV=development node app.js"
Tried to do it like this:

"start": "SET NODE_ENV=development && nodemon app.js"

But in this case logger fails:
var winston = require('winston'),
  ENV = process.env.NODE_ENV; // app.get('env');
        console.log(ENV); //development

function getLogger(module) {
  var path = module.filename.split('/').slice(-2).join('/');

  return new winston.Logger({
    transports: [
      new winston.transports.Console({
        colorize: true,
        level: (ENV == 'development') ? 'debug' : 'error',
        label: path
      })
    ]
  });
}


module.exports = getLogger;

http.createServer(app).listen(app.get('port'), function() {
  log.info('Express server listening on port ' + app.get('port'));
});

If you run it yourself through the console NODE_ENV=development nodemon app.js
Then the log is displayed. And in the case above, the log is not displayed, although process.env.NODE_ENV displays development

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-01-24
@DarCKoder

I will add that if you need cross-platform, then use the cross-env package, something like this:cross-env NODE_ENV=production nodemon app.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question