Express js 4.0 is released now and my express 3-app is not working after updating because app.configure()
was removed in the new version.
My Express 3-config looks like this:
// all environments
app.configure(function()
{
app.use(express.static(__dirname + '/public'));
// ...
});
// NODE_ENV=development only
app.configure('development', function()
{
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
// ...
});
// NODE_ENV=production only
app.configure('production', function()
{
app.use(express.errorHandler());
// ...
});
My Question: What is the best practice for configuring an express 4 app depending on the NODE_ENV environment variable?
Faster testing execution. Getting wider coverage metrics of the code. Allows deploying the same API under flexible and different network conditions. Better separation of concerns and cleaner code.
It is unmaintained Express has not been updated for years, and its next version has been in alpha for 6 years. People may think it is not updated because the API is stable and does not need change. The reality is: Express does not know how to handle async/await .
I suggest if you are making this conversion, you read through the 3.x
to 4.x
conversion guide.
Specifically:
app.configure('development', function() {
// configure stuff here
});
// becomes
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
// configure stuff here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With