Bind expressjs to a specific IP address


Question

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');
1
40
4/3/2012 2:07:06 AM

Accepted Answer

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

Is that not the case?

44
6/1/2015 6:13:31 PM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon