How to determine a user’s IP address in Node.js?

Sometimes, we want to determine a user’s IP address in Node.js.

In this article, we’ll look at how to determine a user’s IP address in Node.js.

How to determine a user’s IP address in Node.js?

To determine a user’s IP address in Node.js, we can use the req.socket.remoteAddress property.

For instance, we write

app.post('/get/ip/address', (req, res) => {
  res.send(req.socket.remoteAddress)
})

to return the user’s IP address that we get from req.socket.remoteAddress as the response.

Conclusion

To determine a user’s IP address in Node.js, we can use the req.socket.remoteAddress property.