Languages
[Edit]
EN

Express.js - get client IP address from request / req

4 points
Created by:
Fletcher-Peralta
778

In this short article, we would like to show how to get a client IP address from a request (req argument) in Express.js server application.

Client IP Address for request in local network - Express.js server application
Client IP Address for request in local network - Express.js server application

Steps:

  1. Integrate below code with your web site,
  2. Run your Express.js server application,
  3. Open one of the following addresses in the web browser:
    • http://localhost:3000/client-ip-address for localhost development,
    • https://my-domain.com:3000/client-ip-address for production.

 

index.js file:

 

request-utils.js file:

Note: IP_HEADERS are useful to get a client IP address when we use some other application that may cover our server, e.g. VirtualServers, load balancers, etc.

 

References

Edit
  1. request-ip - npm
  2. pbojinov/request-ip: A Node.js module for retrieving a request's IP address on the server - Github

Alternative titles

  1. Express.js - determine user's IP address from request / req
  2. Express.js - get client IP address from request / req
  3. Express.js - determine user's IP address from request / req
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join