Can I use other node.js libraries in Meteor?

I played with the idea and wanted to get json from another site. I found with node.js people seem to use http.get to accomplish this, however I found that it is not so simple in Meteor. Is there any other way to do this or a way to access http so that I can call get? I need an interval that could collect data from an external source to increase the data that clients will interact with.

+6
source share
3 answers

It looks like you can get to require like this:

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

Note that this will probably only work on the server, so make sure it is protected by validation on Meteor.is_server .

+8
source

Now it is much easier with Meteor.http . 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); 
+8
source

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 the pacakges.json file and add all the necessary package names and versions.

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

Source: https://habr.com/ru/post/912973/


All Articles