Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind expressjs to a specific IP address

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'); 
like image 697
ReiGarcia Avatar asked Apr 03 '12 02:04

ReiGarcia


People also ask

Can I use Nextjs instead of Express?

Next. js doesn't replace Express and you can use them together. Next. js uses some Node.

What is trust proxy in Express?

Indicates the app is behind a front-facing proxy, and to use the X-Forwarded-* headers to determine the connection and the IP address of the client. NOTE: X-Forwarded-* headers are easily spoofed and the detected IP addresses are unreliable.


2 Answers

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

Is that not the case?

like image 98
Jacob Krall Avatar answered Sep 21 '22 12:09

Jacob Krall


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.

like image 27
Rubin bhandari Avatar answered Sep 20 '22 12:09

Rubin bhandari