res.location()函數用於將響應位置HTTP標頭設置為指定的path參數。本質上是用來設置響應頭的。它不會結束響應,使用完後,您可以編寫響應正文。
用法:
res.location( path )
參數:
- path:它引用在請求的Referer標頭中指定的URL。
快遞模塊的安裝:
- 您可以訪問安裝Express模塊的鏈接。您可以使用此命令安裝此軟件包。
npm install express
- 安裝Express模塊後,可以使用命令在命令提示符下檢查Express版本。
npm version express
- 之後,您可以僅創建一個文件夾並添加一個文件,例如index.js。要運行此文件,您需要運行以下命令。
node index.js
文件名:index.js
var express = require('express');
var app = express();
var PORT = 3000;
app.get('/', function(req, res){
res.location('http://demo.com');
console.log(res.get('location')); // http://demo.com
});
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
});
運行程序的步驟:
- 項目結構將如下所示:
- 確保使用以下命令安裝了Express模塊:
npm install express
- 使用以下命令運行index.js文件:
node index.js
輸出:
Server listening on PORT 3000
- 現在打開瀏覽器並轉到http://localhost:3000 /,現在檢查控製台,您將看到以下輸出:
Server listening on PORT 3000 http://demo.com
相關用法
- p5.js sin()用法及代碼示例
- CSS url()用法及代碼示例
- p5.js str()用法及代碼示例
- PHP dir()用法及代碼示例
- p5.js tan()用法及代碼示例
- p5.js hex()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js cos()用法及代碼示例
- p5.js log()用法及代碼示例
- CSS var()用法及代碼示例
- PHP ord()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- d3.js d3.set.add()用法及代碼示例
注:本文由純淨天空篩選整理自gouravhammad大神的英文原創作品 Express.js | res.location() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。