Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dns server configuration for node.js

Tags:

node.js

dns

I have developed server application in node.js. Right now I access the application using 128.1.1.5:3000. But i want to use a domain name like abc.net to access the application. How can I do this. Please suggest.

like image 359
DeoChandra Avatar asked Apr 15 '26 16:04

DeoChandra


1 Answers

To configure DNS on your local app,you need to do following configuration.

  1. Make an entry of this DNS example abc.net as a host instead of local host while setting up your node server where you are mentioning the localhost host and port detail eg. in app.js file.

Example

const http = require('http');

const hostname = 'abc.net';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
  1. Now open command prompt and type

ipconfig -all

It will list all your IPs. Select the ip of your machine which is preferred one.mostly you can locate this ip by finding the ip which is followed by (preferred) keyword in command prompt.

  1. Now copy this IP address and make an entry of this in system host file.Make sure you have an admin rights to make changes in this file.

Path of host file in Windows C:\Windows\System32\drivers\etc\hosts

  1. Edit this file and scroll to the end and press Enter to copy the ip address corresponding to the DNS which you have configured in node js application as shown below in new line.

    IPaddress(fetched in step 3) abc.net

i.e ipaddress then give space then dns name

  1. Save the file.

  2. Start your node application.

  3. Now try hitting your api from the url abc.net:port/api

like image 85
Shikhar Avatar answered Apr 17 '26 07:04

Shikhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!