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.
To configure DNS on your local app,you need to do following configuration.
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}/`);
});
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.
Path of host file in Windows C:\Windows\System32\drivers\etc\hosts
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
Save the file.
Start your node application.
Now try hitting your api from the url abc.net:port/api
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With