Express.js 中的 app.enabled() 方法
app.enabled() 方法检查设置名称属性是否已启用。它基本检查设置名称的值,如果属性值也是 True,则返回 True。
语法
app.enabled( name )
示例 1
创建一个名为“appEnabled.js”的文件,并复制以下代码段。创建文件后,使用命令“node appEnabled.js”来运行此代码,如下例所示 −
// app.enabled() Method Demo Example // Importing the express module const express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var router = express.Router(); var PORT = 3000; // Checking the foo property console.log("Trust proxy settings are set to: ", app.enabled('trust proxy'));
输出
C:\home
ode>> node appEnabled.js Trust proxy settings are set to: false
示例 2
我们再来看一个示例。
// app.enabled() Method Demo Example // Importing the express module const express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express var router = express.Router(); var PORT = 3000; // Enabling 'trust proxy' settings app.enable('trust proxy'); // Checking the foo property console.log("Trust proxy settings are set to: ", app.enabled('trust proxy'));
输出
C:\home
ode >> node appEnabled.js Trust proxy settings are set to: true
广告