最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - express js 4 - How to configure without app.configure? - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked Apr 10, 2014 at 12:08 bluelDebluelDe 3958 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

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
}
发布评论

评论列表(0)

  1. 暂无评论