Categories
JavaScript Answers

How to bind Express.js to a specific IP address?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *