Use instructions for the url.resolve method in node.js

  • 2020-03-30 04:36:16
  • OfStack

Method description:

Insert or replace the original tag for the URL or href. (you can read the examples if you don't understand)


url.resolve(from, to)

Since this method belongs to the url module, the url module (var url= require(" url ")) needs to be introduced before use.

Receiving parameters:

From                        Source address

To                                Tags that need to be added or replaced


var url = require('url');
var a = url.resolve('/one/two/three', 'four') ,
b = url.resolve('', '/one'),
c = url.resolve('', '/two');
console.log(a +","+ b +","+ c);


Url.prototype.resolve = function(relative) {
  return this.resolveObject(urlParse(relative, false, true)).format();

Related articles: