DEV Community

Rudra Pratap
Rudra Pratap

Posted on

2

http requests are always served at port 80. PROOF!

We know that http requests are by default goes to port 80.
In this article I will prove that this fact is true.

For this demonstration, I am going to create a tiny Nodejs server.

const express = require('express')
const app = express() 
app.get('/',(req,res)=>{
    res.send('hi')
})

const port = 5000
app.listen(port,()=>console.log(`listening on port ${port}`))
Enter fullscreen mode Exit fullscreen mode

Start the server by typing node app.js in the terminal.

Now go to the browser and write the url http://localhost:5000.
The output will be:

Image description

Now, rewrite the url again but omit the port number this time. ie
search http://localhost.
Now you will get error this time:

Image description

You get this error because you made a http request and http requests are resolved on port 80, but your Nodejs server is listening on port 5000 and there is no service running on port 80.

Now the magic is going to happen.
If you want to http://localhost doesn't throw error on the browser, you have to make some changes in the Nodejs file.


const express = require('express')
const app = express() 
app.get('/',(req,res)=>{
    res.send('hi')
})

const port = 80
app.listen(port,()=>console.log(`listening on port ${port}`))

Enter fullscreen mode Exit fullscreen mode

Restart the server and search http://localhost in the browser.
The output is:

Image description

HOLLA! There is no error! And we did wrote the port number in the url.

Thus it is proved that http request are resolved on port 80.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay