Bind expressjs to a specific IP address

node.jsExpress

node.js Problem Overview


How can i bind a expressjs server to a specific IP

Something like

app.listen(8888, '192.168.0.101');

Equivalent to nodejs:

http.createServer(onRequest).listen(8888,'192.168.0.101');

node.js Solutions


Solution 1 - node.js

ExpressJS just passes your parameters down to the http module when you call listen, so your example should work.

Is that not the case?

Solution 2 - node.js

var server = app.listen(3000, '127.0.0.1',onServerListening);

In this case I want the server to respond only to connections using the 127.0.0.1 host name. Not 0.0.0.0, and not localhost. Only 127.0.0.1.

Solution 3 - node.js

app.set('domain', 'myhost.whatever');
app.set('port', process.env.PORT || 8080);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionReiGarciaView Question on Stackoverflow
Solution 1 - node.jsJacob KrallView Answer on Stackoverflow
Solution 2 - node.jsRubin bhandariView Answer on Stackoverflow
Solution 3 - node.jschovyView Answer on Stackoverflow