I am currently running my node / express application in production deployment, and as part of this, I need to make it work in a mode convenient for production (for example, fewer debugs for stdOut, write logs in different places, tell users less when errors occur etc.).
I’m struggling with this a little, because whenever I set a variable of almost any type to call the “production” mode, it does not affect the program’s work when it starts.
When running in dev mode, my code goes through Gulp and runs this script:
#!/usr/bin/env node var debug = require('debug')('ascema'); var app = require('../app'); app.set('port', process.env.PORT || 3000); var server = app.listen(app.get('port'), function() { debug('Express server listening on port ' + server.address().port); });
Which, as you know, is just the generated script run from the express generator.
To launch it in real time, I created an alternative launch for the server (I could hardly use gulp), and live.js runs this:
#!/usr/bin/env node var app = require('./app.js'); app.set('env', 'production'); console.log('running on Port 3000'); var server = app.listen(3000);
But when I use app.get('env') anywhere in the application (for example, in app.js or various dependencies in it), it still returns “development”, and therefore none of my production tasks arise.
What am I doing wrong here?
Many thanks.
Owen C. Jones
source share