Created
March 19, 2017 06:53
-
-
Save gnilchee/7e337c6441ae8107f901ec9a89bde965 to your computer and use it in GitHub Desktop.
Getting your public IP with Nodejs using coffeescript and the result js file for reference (npm install --save coffee-script https)
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
https = require 'https' | |
https.get { host: 'api.ipify.org', path: '/?format=json' }, (res) -> | |
console.log 'statusCode:', res.statusCode | |
console.log 'content-type:', res.headers['content-type'] | |
data = '' | |
res.on 'data', (chunk) -> | |
data += chunk.toString() | |
res.on 'end', () -> | |
console.log 'publicIP:', JSON.parse(data)['ip'] |
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
// Generated by CoffeeScript 1.12.4 | |
(function() { | |
var https; | |
https = require('https'); | |
https.get({ | |
host: 'api.ipify.org', | |
path: '/?format=json' | |
}, function(res) { | |
var data; | |
console.log('statusCode:', res.statusCode); | |
console.log('content-type:', res.headers['content-type']); | |
data = ''; | |
res.on('data', function(chunk) { | |
return data += chunk.toString(); | |
}); | |
return res.on('end', function() { | |
return console.log('publicIP:', JSON.parse(data)['ip']); | |
}); | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment