Express.js 中的 res.app 屬性
res.app 屬性引用了正在由中介軟體使用的 Express 應用程式的例項。
語法
res.app
示例 1
建立一個名為 "resApp.js" 的檔案並複製以下程式碼片段。建立檔案後,使用命令 "node resApp.js" 執行此程式碼,如下例所示 −
// res.app code Demo Example
// Importing the express module
var express = require('express');
// Initializing the express and port number
var app = express();
var PORT = 3000;
// Creating an endpoint
app.get('/', function (req, res) {
console.log(res.app.get('views'));
res.end();
});
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
});為 GET 請求點選以下 URL 端點 − https://:3000/
輸出
C:\home
ode>> node resApp.js Server listening on PORT 3000 /home/express/test/views
示例 2
我們來看一個例子。
// req.range() code Demo Example
// Importing the express module
var express = require('express');
// Initializing the express and port number
var app = express();
var PORT = 3000;
// Creating an endpoint
app.get('/', function (req, res) {
console.log(req.range());
res.end();
});
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
});為 GET 請求點選以下 URL 端點 − https://:3000/
輸出
C:\home
ode>> node resApp.js settings: { 'x-powered-by': true, etag: 'weak', 'etag fn': [Function: generateETag], env: 'development', 'query parser': 'extended', 'query parser fn': [Function: parseExtendedQueryString], 'subdomain offset': 2, 'trust proxy': false, 'trust proxy fn': [Function: trustNone], view: [Function: View], views: '/home/express/test/views', 'jsonp callback name': 'callback' }, locals: [Object: null prototype] { settings: { 'x-powered-by': true, etag: 'weak', 'etag fn': [Function: generateETag], env: 'development', 'query parser': 'extended', 'query parser fn': [Function: parseExtendedQueryString], 'subdomain offset': 2, 'trust proxy': false, 'trust proxy fn': [Function: trustNone], view: [Function: View], views: '/home/mayankaggarwal/mysql-test/views', 'jsonp callback name': 'callback' } }, mountpath: '/', _router: { [Function: router] params: {}, _params: [], caseSensitive: false, mergeParams: undefined, strict: false, stack: [ [Layer], [Layer], [Layer] ] } }
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP