Razor
Razor

Reputation: 720

Get the outside IP of the server the webapp is hosted on

How can I get the global IP of the server?

I could do a http request to 'http://wtfismyip.com/json' and get the IP address.

Is there a way to get the IP (or dns) whitout doing an outside request? I can't find anything on the 'process.env' or 'os' object.

I use nodejs with express and deploy to heroku.

Upvotes: 2

Views: 111

Answers (1)

OneHoopyFrood
OneHoopyFrood

Reputation: 3969

Simple answer: No. You'll need some kind of outside source. That source could be as local as the router if you had access to it, but it's more work than it's worth. And if you're on a hosting solution that's out anyway.

I assume your reason for wanting to get this quickly is for speed optimization? If so then I recommend you not worry about it. It's such a small action it won't have any lasting impact.

Now that I think about it; you should already know your public IP! If it's a hosted solution it ought not to change so you can get it once and just hard-code it into your project. I have no experience with heroku though, so it's possible they use a dynamic IP.

Upvotes: 1

Related Questions