86.express里面的app.configure作用

本文介绍了Express3.0中app.configure方法的使用方式及其实现原理,通过实例对比展示了如何利用条件语句来替代该方法,从而实现更加灵活的应用配置。

以下摘自 express 3.0 的 文档

app.configure([env], callback)

Conditionally invoke callback when env matches app.get(‘env’), aka process.env.NODE_ENV. This method remains for legacy reason, and is effectively an if statement as illustrated in the following snippets. These functions are not required in order to use app.set() and other configuration methods.

里面说 app.configure 是以前的版本遗留下来的,完全可以用条件判断语法取代。

文档里还举例说明了:

app.configure(function() { app.set('title', 'My Application'); });

app.set('title', 'My Application');

是等价的,都是对所有环境有效。而

app.configure('development', function(){ app.set('db uri', 'localhost/dev'); })

if ('development' == app.get('env')) { app.set('db uri', 'localhost/dev'); }

是一个效果。

转载于:https://www.cnblogs.com/sharpest/p/8214808.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值