Answer the question
In order to leave comments, you need to log in
How to change Node port?
Hi all. I recently started learning Node, and after reading a lot of information, I still did not understand how to change the port on the server itself. Many examples simply indicate how to change a line in the code itself to listen on some port (80 or 8080). But if you need to hang Node on port 1234, for example, is it impossible or what? Thank you.
Answer the question
In order to leave comments, you need to log in
If you use express:
var app = require('express')();
var listener = app.listen(8888, function(){
console.log('Listening on port ' + listener.address().port); //Listening on port 8888
});
If not, then: https://nodejs.org/api/http.html#http_server_liste...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question