Node.js url.parse() and pathname property

后端 未结 5 1544
遇见更好的自我
遇见更好的自我 2020-12-14 06:33

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

5条回答
  •  执笔经年
    2020-12-14 06:52

    pathname is the part of URL section that comes after server and port. In,var pathname = url.parse(request.url).pathname; the request.url ,requests the url from the URL Section which is the set of the component - IP address of localhost , port no and file pathname.

    Let understand it by an example suppose this is the url to be requested to server http://127.0.0.1:8082/ but for response to the client there should be an html file let it be index.html then http://127.0.0.1:8080/index.html and this html file is the .pathname to the url. So,In var pathname = url.parse(http://127.0.0.1:8080/index.html).pathname the pathname is index.html that is response to client.

提交回复
热议问题