I cannot access the NODE_ENV variable when I try to make configuration changes to the config/server.jsSails.js file . I want to set the serverOptionsproperty flag expressand bind ssl certificates - but only for production.
Assuming I started the server with node app.js --prod
This does not work:
module.exports = { ... };
console.log(process.env.NODE_ENV); // undefined
But it works:
module.exports = { ... };
setTimeout(function () {
console.log(process.env.NODE_ENV);
}, 1000);
Basically all I want to do is:
module.exports = (function () {
var env = process.env.NODE_ENV,
ret = { express: {} };
if (env == 'production') {
ret.express.serverOptions = { key: ..., cert: ... };
}
return ret;
}());
I have seen similar answers, such as https://stackoverflow.com/a/3129381/2129 , but I can’t figure out how they should work when mine doesn’t.
source
share