Node.js url.parse() and pathname property

后端 未结 5 1550
遇见更好的自我
遇见更好的自我 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 07:01

    Here's an example:

    var url = "https://u:p@www.example.com:777/a/b?c=d&e=f#g";
    var parsedUrl = require('url').parse(url);
    ...
    protocol  https:
    auth      u:p
    host      www.example.com:777
    port      777
    hostname  www.example.com
    hash      #g
    search    ?c=d&e=f
    query     c=d&e=f
    pathname  /a/b
    path      /a/b?c=d&e=f
    href      https://www.example.com:777/a/b?c=d&e=f#g
    

    And another:

    var url = "http://example.com/";
    var parsedUrl = require('url').parse(url);
    ...
    protocol http:
    auth     null
    host     example.com
    port     null
    hostname example.com
    hash     null
    search   null
    query    null
    pathname /
    path     /
    href     http://example.com/
    

    Node.js docs: URL Objects

提交回复
热议问题