Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get request's remote client IP in Node.js? #2994

Open
movahhedi opened this issue Jun 19, 2024 · 6 comments
Open

How to get request's remote client IP in Node.js? #2994

movahhedi opened this issue Jun 19, 2024 · 6 comments
Labels
enhancement New feature or request.

Comments

@movahhedi
Copy link

What is the feature you are proposing?

How can i get the IP of the remote client?

I've seen https://hono.dev/docs/helpers/conninfo but there isn't anything for Node.js.

In Koa, its ctx.request.ip. code

May be useful:

@movahhedi movahhedi added the enhancement New feature or request. label Jun 19, 2024
@EdamAme-x
Copy link
Contributor

hi @movahhedi
It depends on which deployment service you use.

@movahhedi
Copy link
Author

Hello @EdamAme-x

Node.js, PM2, nginx/Apache.

@NicoPlyley
Copy link
Contributor

Hi @movahhedi,
You can pass the IP address as a header using nginx and a reverse proxy see here where this issue was discussed more

@movahhedi
Copy link
Author

Isn't this feature good enough to be included in Hono [for Node]?
Since it's there in Koa, It should be technically possible.

@EdamAme-x
Copy link
Contributor

I don't think Node.js by itself is often used to build servers, what do you think? I think most would use a reverse proxy or a deployment service.

implement in Koa
https://github.com/koajs/koa/blob/b89e19a27509c96d27af722f9951e0d72cb41eb5/lib/request.js#L455

@EdamAme-x
Copy link
Contributor

If you implement it, you can add it to the getConninfo helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

3 participants