Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created March 19, 2017 06:53
Show Gist options
  • Save gnilchee/7e337c6441ae8107f901ec9a89bde965 to your computer and use it in GitHub Desktop.
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)
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']
// 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