I have a simple node.js program running on my machine and I want to get local IP address of PC on which is my program running. How do I get it with node.js?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Keeping track of variable instances
hope this helps
Based on a comment above, here's what's working for the current version of Node:
The comment on one of the answers above was missing the call to
values()
. It looks likeos.networkInterfaces()
now returns an object instead of an array.Similar to other answers but more succinct:
Here's a neat little one-liner for you which does this functionally:
for Linux and MacOS uses, if you want to get your IPs by a synchronous way, try this.
the result will be something like this.
One liner for MAC os first localhost address only.
When developing apps on mac os, and want to test it on the phone, and need your app to pick the localhost ip automatically.