kuno / GeoIP

GeoIP binding for nodejs(>=0.10) and iojs
GNU Lesser General Public License v2.1
414 stars 129 forks source link

Newbie issue. ReferenceError: geoip is not defined #36

Closed kojilab closed 11 years ago

kojilab commented 12 years ago

Hi,

I'm a nodejs newbie and I'm playing with railwayjs with GeoIP.

I've done

sudo npm install geoip

Then in my controller, I've got

require('geoip'); // this doesn't return any error as a module that is not found

then

var City = geoip.City; var citydata = new City('../../data/geo/GeoLiteCity.dat');

And I'm getting the error in the title.

Thanks for helping a newbie like me.

kuno commented 12 years ago

In node, require is a function not a statement (like ruby?)

You SHOULD assign the return value of require('geoip') to a javascript variable, like this:

var geoip = require('geoip');

This should solve your problem.

kojilab commented 12 years ago

Thanks. IT works now. I know JS very well but I guess my brain is so backend oriented I missed that one

kuno commented 12 years ago

Yeah, that's one of the primary reasons why people loves node, : )

kojilab commented 12 years ago

Yes. Tired of switching languages.

It works great by the way.

Thanks for the great library.

kuno commented 12 years ago

You are welcome to this community.

sanvuthy commented 11 years ago

Can I use it with rails?

kuno commented 11 years ago

@sanvuthy

this is only for nodejs.