Created
August 20, 2017 06:41
-
-
Save imesh/99482c814e2fb59494e8a981fdaea64c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const os = require('os'); | |
const app = express() | |
app.get('/', function (req, res) { | |
res.send('Response from ' + getIPAddress()) | |
}) | |
function getIPAddress() { | |
var interfaces = require('os').networkInterfaces(); | |
for (var devName in interfaces) { | |
var iface = interfaces[devName]; | |
for (var i = 0; i < iface.length; i++) { | |
var alias = iface[i]; | |
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) | |
return alias.address; | |
} | |
} | |
return '0.0.0.0'; | |
} | |
app.listen(8080, function () { | |
console.log('Echo server listening on port 8080!') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment