How to Extract Base URL From Subdomain in Javascript and Node.js Full Tutorial 2020

You are currently viewing How to Extract Base URL From Subdomain in Javascript and Node.js Full Tutorial 2020

 

Live Demo

 

 

 

You can see the live demo of the app here

 

 

 

Get Started

 

 

In order to get started we need to install a node.js dependency called as psl which will actually extract the base url from the subdomain so kindly first of all initialize a node.js project

 

 

npm init -y

 

 

This will create the package.json file and then install psl dependency like this

 

npm i psl

 

 

Now we want to create a index.js file and copy paste the following code

 

 

 

 

 

 

Now we just need to make a AJAX Request from the html file to this node.js post request to get the base url from the subdomain.

Now create a views folder inside your root project and inside it you create extractbaseurl.ejs file and copy paste the following code

 

views/extractbaseurl.ejs

 

 

 

 

 

Screenshots

 

 

 

 

 

DOWNLOAD SOURCE CODE

 

 

Leave a Reply