Hey Guys, hope you all are doing great !. So couple a weeks ago a created a node module iplocate its a middleware which let me gets the location of the request and where it is coming from. I have used freegeoip an awesome service for getting this location of a particular ip address. You can make upto 10000 request per hour for free.
So Lets get Started
You can install it using
1 |
npm install iplocate --save |
Just simply require it in your project and use it in your App.
1 2 3 |
let iplocate = require('iplocate'); app.use(iplocate); |
And You will get the location object in your route attached on a request object. In case of an error req.locationError will be populated.
1 2 3 4 5 6 7 8 9 |
router.get('api/route',function(req,res){ if(req.locationError){ // In case of Any error locationError will be populated console.log('req.locationError ',req.locationError) }else { // The location object will be attached to request console.log('req.location',req.location) } }); |
wasn’t that easy?. well that’s it for now Stay tune for more blogs on Node.js and Javascript.
Have a Great day or Night 🙂