Permalink
Browse files

Step 1.5: Add ip_grabber helper

  • Loading branch information...
DAB0mB committed Dec 12, 2016
1 parent 44dbaa0 commit 7dfe84a435c5b5aae8930ebfd5b8771ba4b373e5
Showing with 23 additions and 0 deletions.
  1. +23 −0 helpers/ip_grabber.js
@@ -0,0 +1,23 @@
const Os = require("os");

// Grab local IP address of which the NodeJS process runs on
function local() {
let interfaces = Os.networkInterfaces();
let addresses = [];

for (let k in interfaces) {
for (let k2 in interfaces[k]) {
let address = interfaces[k][k2];

if (address.family == "IPv4" && !address.internal) {
addresses.push(address.address);
}
}
}

return addresses[0];
}

module.exports = {
local
};

0 comments on commit 7dfe84a

Please sign in to comment.