Sometimes, we want to bind Express.js to a specific IP address.
In this article, we’ll look at how to bind Express.js to a specific IP address.
How to bind Express.js to a specific IP address?
To bind Express.js to a specific IP address, we call listen
with the IP address as the 2nd argument.
For instance, we write
const server = app.listen(3000, "127.0.0.1", onServerListening);
to call app.listen
with the port, IP address string, and the onServerListening
callback function that runs when the server is started.
This will bind the Express app to 127.0.0.1
Conclusion
To bind Express.js to a specific IP address, we call listen
with the IP address as the 2nd argument.