开发者

How can I allocate URL objects in node.js?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜