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}`))
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:
Now, rewrite the url again but omit the port number this time. ie
search http://localhost
.
Now you will get error this time:
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}`))
Restart the server and search http://localhost
in the browser.
The output is:
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.
Top comments (0)