Created
July 1, 2014 03:32
-
-
Save konsumer/ef1f4aae96cb750f30a8 to your computer and use it in GitHub Desktop.
save these 2 files, run `npm install`
This file contains 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
{ | |
"name": "testdir", | |
"version": "0.0.0", | |
"main": "index.js", | |
"dependencies": { | |
"randopeep": "^0.2.0", | |
"request": "^2.36.0" | |
} | |
} |
This file contains 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
var randopeep = require('randopeep'), | |
request = require('request'); | |
var newguy = { | |
gender: 'male', | |
origin: 'netrunner' | |
}; | |
var options = Object.create(newguy); | |
options.prefix=false; | |
newguy.name = randopeep.name(options); | |
newguy.email = randopeep.internet.email(newguy.name); | |
newguy.ip = randopeep.internet.ip(); | |
function randomLocation(cb){ | |
var ip = randopeep.internet.ip(); | |
request('http://freegeoip.net/json/' + ip, function (er, res, body) { | |
if (er) return cb(er); | |
var info = JSON.parse(body); | |
if (!info || !info.zipcode) return randomLocation(cb); | |
cb(null, info); | |
}); | |
} | |
randomLocation(function(er, info){ | |
if (er) return console.log(er); | |
newguy.ip = info.ip; | |
newguy.area_code = info.area_code | |
delete info.ip; | |
delete info.metro_code; | |
delete info.area_code; | |
newguy.address = info; | |
newguy.address.street = randopeep.address.streetAddress(); | |
console.log(newguy); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment