Node.js Project to Merge or Join Multiple Website URLs Using url-joiner Library in Javascript Full Tutorial For Beginners

Node.js Project to Merge or Join Multiple Website URLs Using url-joiner Library in Javascript Full Tutorial For Beginners

 

Welcome folks today in this blog post we will be merging or joining multiple website urls using url-joiner library in node.js and javascript. All the full source code of application is shown below.

 

 

 

Get Started

 

 

 

In order to get started we need to install url-joiner library by issuing the npm command

 

npm i url-joiner

 

After executing this command your library will be installed and now create an index.js file and copy paste the following code

 

index.js

 

 

const { getUrlParts } = require('url-joiner');
 
console.log(getUrlParts("https://example?name=ken"));

 

 

Extracting parts from url

 

So now if you execute this

 

 

As you can see that it returned array of url parts actual url and the query string

 

Now we will look on how to join a single url with the help of this library

 

const { joinUrl } = require('url-joiner');
 
console.log(joinUrl("https://domain.name", "name=ken"));

 

 

 

READ  Build a Date Time Calculator Using Moment.js Library in Vanilla Javascript Full Project For Beginners

 

joinPath(url, …paths)

 

Now we will be merging or joining multiple paths or urls like this

 

const { joinPath } = require('url-joiner');
 
console.log(joinPath("https://domain.name", "users", "id", "preview"));

 

 

 

 

parseSearch(search)

 

Now we will be extracting the query parameters from the url like this

 

const { parseSearch } = require('url-joiner');
 
console.log(parseSearch("name=james&surname=willis"));

 

 

 

 

 

mergeSearch(params, search)

 

 

Now we will be merging or joining url params or query parameters inside urls like this

 

const { mergeSearch } = require('url-joiner');
 
console.log(mergeSearch(
  {
    name: "ken",
    age: "21"
  },
  "name=james&surname=willis"
))

 

Leave a Reply