D
D
Dmitry2015-08-31 16:39:14
linux
Dmitry, 2015-08-31 16:39:14

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

1 answer(s)
A
Alexander Wolf, 2015-08-31
@dmitrydeco

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 question

Ask a Question

731 491 924 answers to any question