开发者

How can I allocate URL objects in node.js?

开发者 https://www.devze.com 2023-01-15 14:02 出处:网络
How can I allocate an开发者_运维问答 instance of a URL object using node.js from an existing url string?

How can I allocate an开发者_运维问答 instance of a URL object using node.js from an existing url string?

Something like this:

var url = require('url');
var myurl = new url("http://google.com/blah");

I can't seem to find any mention/example of this anywhere.


var url = require('url');
var myurl = url.parse('http://google.com/blah');

You can now use

myurl.hostname // google.com
myurl.pathname // /blah

and so on..

http://nodejs.org/api.html#url-302

You very rarely (if ever) need to use the new keyword in relation to the built-in modules, as long as you use the documented functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消