pat310 / google-trends-api

An API layer on top of google trends
https://www.npmjs.com/package/google-trends-api
MIT License
894 stars 178 forks source link

Not getting how to have api functioning with 'require' #27

Closed romulo-rocha closed 7 years ago

romulo-rocha commented 8 years ago

I know this is an ignorance of mine and not an issue with the code. Firstly, I'd like to thank the author of this repository.

Could you explain how do I get this api functioning on my application? I know it all starts with:

var googleTrends = require('google-trends-api') But that's exactly where I am failing to succeed at using the plugin. :( Now I know it's dumb, lol but please have mercy on me.

I've downloaded requirejs from http://requirejs.org/ and included it on my page. But when I manage to require the plugin, it doesn't recognize "module.exports" or the "_dirname" variable. I don't quite understand this require Javascript solution.

Thanks

pat310 commented 8 years ago

@romulo-rocha I'll have to rewrite some things to add support for directly using the library in the browser (assuming there are no CORS issues). For now, if you have a node back-end you should be able to require the library in there. I'll keep this issue open until that is complete.

romulo-rocha commented 8 years ago

Thank you so much for your support!

Well, I am trying to use it on my web application which is not using a Node back-end (maybe that's the problem). I am working with Laravel framework (PHP) and AngularJS. If there's a way to use it in regular back-end services, I'd be very appreciated.

Take care!

Dayjo commented 8 years ago

You might be able to get this working with something like browserify which allows you to require, and then compiles for web. However some of the modules used ('require-promise') may not work, and potentially would need to be switched out for an XHR library.

pat310 commented 8 years ago

Thanks @Dayjo. I'm planning to change the package up to remove request and request-promise dependencies and also incorporate the ability to make requests from the front-end

lakshsyal123 commented 8 years ago

Hey i installed it by using browserify but its says

bundle.js:1 Uncaught Error: Cannot find module '/node_modules/google-trends-api/lib/utils/index.js'

Well can anyone explain how can i resolve this error.

garann commented 7 years ago

I'm getting basically the same error as @lakshsyal123 and am also using Browserify via wzrd. The exact text is: Uncaught Error: Cannot find module '/node_modules/google-trends-api/lib/utils/'

I went through and changed a few of the requires from e.g. require(__dirname + '/lib/utils/') to require('./lib/utils/') and that allowed execution to proceed to the next dependency.

pat310 commented 7 years ago

I'll be adding a patch soon that will remove the node specific code so the library can be used in the browser.

pat310 commented 7 years ago

Closed in PR #44