Node.js Project to Check HTTP Status Code (Active or Dead),Header of Website Link or URL Using link-check Library in Javascript Full Project For Beginners

Node.js Project to Check HTTP Status Code (Active or Dead),Header of Website Link or URL Using link-check Library in Javascript Full Project For Beginners

 

Welcome folks today in this blog post we will be checking the http status of website link or url in javascript and node.js. We will be using link-check library for this purpose. All the source code of the application will be shown below.

 

 

 

Get Started

 

 

 

In order to get started we need to install the link-check library by using the npm command

 

npm i link-cbeck

 

After installing the library we need to create an index.js file and copy paste the following code

 

index.js

 

 

'use strict';

const linkCheck = require('link-check');

linkCheck('https://codingshiksha.com', function (err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log(result)
    console.log(`${result.link} is ${result.status}`);
});

 

 

Here as you can see we are passing the url codingshiksha.com and then we are using this link-check library to get the https status code of the domain and other information whether the domain or url is active or not

READ  Build a Unit Weight (Mass) Conversion Calculator in HTML5 CSS3 and Javascript Full Project For Beginners

 

If you run this node.js script you will see the below information inside the object

 

 

 

 

Now if you pass a wrong domain or url so it will show an eror status code like this

 

 

'use strict';

const linkCheck = require('link-check');

linkCheck('https://codingshisdfsdfsdksha.com', function (err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log(result)
    console.log(`${result.link} is ${result.status}`);
});

 

 

Now if you run this node.js script you will see the following screenshot

 

 

 

 

As you can see that it is saying that the link is dead

 

Leave a Reply