Skip to content
Sign upLog in
← Back to Community

Node.js Chatroom

Profile icon
jonster5

Does anybody have any Idea how to connect to the correct port?

Answered by TheDrone7 [earned 5 cycles]
View Answer
Voters
Profile icon
stevenhuang2025
Profile icon
jonster5
Comments
hotnewtop
Profile icon
TheDrone7

Don't provide a port number, it will automatically connect to one.

Profile icon
jonster5

@TheDrone7
What should i put in place of the port number?

Profile icon
TheDrone7

@jonster5
nothing, don't pass a port number. For example:-

let listener = app.listen(); console.log(`Listening to port number ${listener.address().port}`);
Profile icon
jonster5

@TheDrone7
Great! this worked. Thanks for the help, I'm still learning how to use Node.js and Express

Profile icon
TheDrone7

@jonster5
you're welcome, please mark my comment as the right answer.

Profile icon
hyperupcall

That's quite interesting. When I do my setup, I can use the port number just fine.
Most common, you'll find people setting the port numbers as:

let port = process.env.PORT || 3000;

So if replit ever decides to set the environment variable PORT, it will automatically work. If it's some falsy value, then port will be set to 3000, kinda like a fallback.

Hopefully I was able to help! 😜

Profile icon
stevenhuang2025

HELLO CAN I PLEASE FORK THIS

@jonster5

Profile icon
stevenhuang2025

Can I fork this? I want to be able to chat with my friends! :)

Profile icon
stevenhuang2025

Can you chat in the chatroom?

Profile icon
jonster5

@Steven_The_GuyT You can now. It works.

Profile icon
stevenhuang2025

@jonster5
Oh, someone join me!