Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express js 4 - How to configure without app.configure?

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?

like image 442
bluelDe Avatar asked Apr 10 '14 12:04

bluelDe


People also ask

Why we have to keep separate Express APP js and server js?

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.

Is Express JS unmaintained?

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 .


1 Answers

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
}
like image 142
loganfsmyth Avatar answered Oct 17 '22 01:10

loganfsmyth