Node.js Express Domain Age Checker and Domain WHOISINFO Checker Web App Deployed on Website + Source Code 2020

Node.js Express Domain Age Checker and Domain WHOISINFO Checker Web App Deployed on Website + Source Code 2020

 

 

Welcome folks today in this tutorial we will be building two web apps and we will be deploying it to my website. The names of the web apps are free domain age checker and free domain whoisinfo checker web app respectively. All the source code of the apps are given below.

 

Live Demo of App

 

Live Demo of Domain WHOISINFO Checker

 

Live Demo of Domain Age Checker

 

Get Started

 

In order to get started you need to install the following dependencies inside your node.js project

 

npm init -y

 

npm i express moment whois-json ejs is-valid-domain

 

The list of dependencies are as follows

 

express : Express will be the backend server on which the app lives

 

ejs Next comes the template engine of html which is ejs.

 

whois-json This is the dependency of node which will return the whoisinfo information about the domain which the user will provide inside the json format

 

moment Moment is the date time library for node. With the help of this library we will be calculating the domain age of the website

 

is-valid-domain This is the library from which we know whether the entered domain is valid or not

 

Install all these dependencies with the help of the above command and then open the project inside the visual studio code

 

And now we need to make the index.js file and copy paste the following code to it

 

 

const moment = require("moment");

const whoisinfo = require("whois-json");

const bodyParser = require('body-parser')

var isValidDomain = require("is-valid-domain");

const express = require('express')

const app = express()

app.use(bodyParser.json())

app.use(bodyParser.urlencoded({extended:false}))
app.set('view engine','ejs')

app.get("/domainwhoisinfo", (req, res) => {
  res.render("domainwhoisinfo", {
    title:
      "Whois Lookup Info Domain Availability & Registrar Checker - FreeMediaTools.com",
    data: "",
    flag: false,
    date: "",
    domainAge: "",
  });
});

app.get("/domainagechecker", (req, res) => {
  res.render("domainagechecker", {
    title:
      "Check Domain Age Online - Website Age Checker - Domain Age Checker - FreeMediaTools.com",
    data: "",
    flag: false,
    date: "",
    domainAge: "",
  });
});

app.listen(5000)

 

See also  How to Embed Twitter API Feed Posts,Hashtags,Media Images on Website in Javascript Full Project For Beginners

 

Now we need to make the templates inside the views folder. So make the views folder inside the root directory and inside it make two files

 

domainwhoisinfo.ejs

 

domainagechecker.ejs

 

domainwhoisinfo.ejs

 

 

<div class="container">
          <h1 class="text-center">
              Domain WhoisInfo Checker
          </h1>
          <form action="/domainwhoisinfo" method="post">
            <div class="form-group">
                <label for="domain">Domain URL:</label>
                <input class="form-control" type="text" name="domain" id="" placeholder="Domain name" required>
            </div>
            <div class="form-group">
                <button class="btn btn-block btn-danger">
                    Get WhoisInfo Data
                </button>
            </div>
            <%if (flag) { %>
                <table class="table table-striped">
                    <thead>
                      <tr>
                        <th>Domain Name</th>
                        <th>RegistrarWhoisServer</th>
                        <th>RegistrarUrl</th>
                        <th>Registrar</th>
                        <th>Creation Date</th>
                        <th>Domain Age</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                        <td><%=data.domainName%></td>
                        <td><%=data.registrarWhoisServer%></td>
                        <td><%=data.registrarUrl%></td>
                        <td><%=data.registrar%></td>
                        <td><%=date%></td>
                        <td><%=domainAge%></td>
                      </tr>
                    </tbody>
                  </table>
            <% } %>
            <br><br>    
        </form>
        <br><br>

 

 

domainagechecker.ejs

 

 

<div class="container">
          <h1 class="text-center">
              Domain Name Age Checker
          </h1>
          <form action="/domainagechecker" method="post">
            <div class="form-group">
                <label for="domain">Domain URL:</label>
                <input class="form-control" type="text" name="domain" id="" placeholder="Domain name" required>
            </div>
            <div class="form-group">
                <button class="btn btn-block btn-danger">
                    Get Domain Age
                </button>
            </div>
        </form>
        <%if (flag) { %>
            <table class="table table-striped">
                <thead>
                  <tr>
                    <th>Domain Name</th>
                    <th>Creation Date</th>
                    <th>Domain Age</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td><%=data.domainName%></td>
                    <td><%=date%></td>
                    <td><%=domainAge%></td>
                  </tr>
                </tbody>
              </table>
        <% } %>
        <br><br>

 

 

 

Now inside index.js we will make the post request to get the domain who is info and domain age like this

See also  How to Download 2D Canvas PNG Image in Browser Using Javascript Full Project For Beginners

 

 

app.post("/domainwhoisinfo", async (req, res) => {
  var domain = req.body.domain;

  var results = await whoisinfo(domain);

  var date = moment(results.creationDate).format("YYYY-MM-DD");
  var currentDate = moment(new Date()).format("YYYY-MM-DD");

  console.log(date);
  console.log(currentDate);

  var a = moment(date);
  var b = moment(currentDate);

  var years = b.diff(a, "year");
  a.add(years, "years");

  var months = b.diff(a, "months");
  a.add(months, "months");

  var days = b.diff(a, "days");

  var domainAge = years + " years " + months + " months " + days + " days";

  console.log(years);
  console.log(months);
  console.log(days);

  //console.log(year + "-" + month + "-" + dt);

  res.render("domainwhoisinfo", {
    title:
      "Whois Lookup Info Domain Availability & Registrar Checker - FreeMediaTools.com",
    data: results,
    flag: true,
    date: date,
    domainAge: domainAge,
  });
});

app.post("/domainagechecker", async (req, res) => {
  var domain = req.body.domain;

  var results = await whoisinfo(domain);

  var date = moment(results.creationDate).format("YYYY-MM-DD");
  var currentDate = moment(new Date()).format("YYYY-MM-DD");

  console.log(date);
  console.log(currentDate);

  var a = moment(date);
  var b = moment(currentDate);

  var years = b.diff(a, "year");
  a.add(years, "years");

  var months = b.diff(a, "months");
  a.add(months, "months");

  var days = b.diff(a, "days");

  var domainAge = years + " years " + months + " months " + days + " days";

  console.log(years);
  console.log(months);
  console.log(days);

  //console.log(year + "-" + month + "-" + dt);

  res.render("domainagechecker", {
    title:
      "Check Domain Age Online - Website Age Checker - Domain Age Checker - FreeMediaTools.com",
    data: results,
    flag: true,
    date: date,
    domainAge: domainAge,
  });
});

 

 

 

Screenshot

 

 

 

 

 

 

Leave a Reply