express 输出html为空,node.js – 如何在Express中输出漂亮的html?

在你的主要app.js或什么是它的地方:

Express 4.x

if (app.get('env') === 'development') {

app.locals.pretty = true;

}

快递3.x

app.configure('development', function(){

app.use(express.errorHandler());

app.locals.pretty = true;

});

快速2.x

app.configure('development', function(){

app.use(express.errorHandler());

app.set('view options', { pretty: true });

});

我把漂亮的打印在开发中,因为你会想要更高的效率与生产中的“丑陋”。当您在生产环境中部署时,确保设置环境变量NODE_ENV = production。这可以通过在package.json的’script’字段中使用的sh脚本来完成,并执行以启动。

Express 3 changed这是因为:

The “view options” setting is no longer necessary, app.locals are the local variables merged with res.render()’s, so [app.locals.pretty = true is the same as passing res.render(view, { pretty: true }).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值