Node.js Tutorial to Extract Base or Root URL From Subdomain Website URL Using get-base-url Library in Javascript Full Project For Beginners

 

 

Installation

 

 

 

npm i get-base-url

 

 

 

Usage

 

 

 

Get base url
Get the base url (domain with protocol) of an string or the current one.

Example
import getBaseUrl from "get-base-url"
const getBaseUrl = require("get-base-url").default

getBaseUrl("https://maps.google.com/sub/sub2")   // https://maps.google.com

getBaseUrl("maps.google.com/sub/sub2")           // https://maps.google.com

getBaseUrl("google.com")                         // https://google.com

getBaseUrl()                                     // The current url if in a browser

getBaseUrl("relative")                           // The current url if in a browser

getBaseUrl("./relative")

Leave a Reply