(express.js)有什么app.set函数? [英] What app.set function does (express.js)?

查看:73
本文介绍了(express.js)有什么app.set函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是node.js的新手,正在通过一个示例无法理解app.set('title','My Site');请帮忙吗?

I am new to node.js and was going through an example could not understand app.set('title', 'My Site'); does please help?

推荐答案

您可以使用express实例存储和检索变量.在这种情况下,您可以将标题设置为我的网站",以后再使用类似的

You can use the express instance to store and retrieve variables. In this case, you can set the title to be "My Site" and retrieve it later with something like

var title = app.get('title');

无需声明和保留全局变量.

without the need to declare and keep a global variable messing around.

参数名称没有任何意义.您可以

The name of the parameter means nothing. You could do

app.set('jabberwocky', 'correct battery horse staples');

也是.例如,如果您将翡翠用于玉器,则可能需要在模板中沿线检索"jabberwocky"的值.

as well. If you're using express with jade, for example, you might need to retrieve the value of 'jabberwocky' in a template, further along the line.

这篇关于(express.js)有什么app.set函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆