Node.js url.parse() 和 pathname 属性 [英] Node.js url.parse() and pathname property
本文介绍了Node.js url.parse() 和 pathname 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读一本关于 node.js 的入门书,名为 The Node Beginner Book,在下面的代码(书中给出)中,我不明白 pathname 属性挂起的意义关闭解析方法.所以我想知道它在做什么.我不清楚此方法的文档
I'm reading a getting started book on node.js called The Node Beginner Book and in the code below (given in the book) I don't understand the significance of the pathname property hanging off the parse method. So I would like to know what it is doing. The documentation for this method is not clear to me
var pathname = url.parse(request.url)**.pathname;**
var http = require("http");
var url = require("url");
function start(route, handle) {
function onRequest(request, response) {
var pathname = url.parse(request.url).pathname; // I don't understand the pathname property
console.log("Request for " + pathname + " received.");
route(handle, pathname);
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
推荐答案
pathname
是 URL 的路径部分,位于主机之后和查询之前,包括初始斜杠(如果存在).
pathname
is the path section of the URL, that comes after the host and before the query, including the initial slash if present.
例如:
url.parse('http://stackoverflow.com/questions/17184791').pathname
会给你:
"/questions/17184791"
这篇关于Node.js url.parse() 和 pathname 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文