Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: What is default server's port? [duplicate]

Tags:

node.js

We often see example hello world code for Node that creates an Http Server, starts listening on a port:

const http = require('http');
const server = http.createServer((req, res) => {
    console.log("Hello World!!!");
});
server.listen();   //This will start our node server

So, in above what is the default server's port in which it is started?

like image 718
Vipul Kumar Avatar asked Sep 06 '25 04:09

Vipul Kumar


1 Answers

If you check the expressjs official documentation of app.listen([port[, host[, backlog]]][, callback]) method here

You see that there comes: If port is omitted or is 0, the operating system will assign an arbitrary unused port, which is useful for cases like automated tasks (tests, etc.).

like image 165
Edson Magombe Avatar answered Sep 08 '25 19:09

Edson Magombe