6

I was playing around with an idea and wanted to get some json from another site. I found with node.js people seem to use http.get to accomplish this however I discovered it wasn't that easy in Meteor. Is there another way to do this or a way to access http so I can call get? I wanted an interval that could collect data from an external source to augment the data the clients would interact with.

3 Answers 3

8

Looks like you can get at require this way:

var http = __meteor_bootstrap__.require('http'); 

Note that this'll probably only work on the server, so make sure it's protected with a check for Meteor.is_server.

Sign up to request clarification or add additional context in comments.

4 Comments

any idea on how to get transitive dependencies to work? Try aws-lib for example.
Meteor.is_server is now Meteor.isServer
also add var require = __meteor_bootstrap__.require; to use the require syntax you're used to.
debergalis's answer should be upvoted now that Meteor.http has been added.
8

This is much easier now with Meteor.http. First run meteor add http, then you can do something like this:

// common code stats = new Meteor.Collection('stats'); // server code: poll service every 10 seconds, insert JSON result in DB. Meteor.setInterval(function () { var res = Meteor.http.get(SOME_URL); if (res.statusCode === 200) stats.insert(res.data); }, 10000); 

Comments

0

You can use Meteor.http if you want to handle http. To add other node.js libraries you can use meteorhacks:npm

meteor add meteorhacks:npm

Create apacakges.json file and add all the required packages name and versions.

{ "redis": "0.8.2", "github": "0.1.8" } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.