Using npm's request inside Meteor

Does anyone here ever used npm’s request inside Meteor ?

I have node.js code that uses npm’s request and I just want to use that code inside Meteor without having to convert to Meteor’s HTTP.

Whether it’s better if I just use npm’s request or I must convert to Meteor’s HTTP ?

You may find this useful:

(npm request repackaged for Meteor)

Does that mean there is no problem with the use of npm’s request ?
(I have see your link, package’s author just use Meteor.wrapAsync to wrap npm’s request).

1 Like

Anyone using request with Meteor 1.3 (beta.12)? Currently having some issues with this NPM dependency, I get this at startup:
W20160302-09:47:50.954(1)? (STDERR) Error: ENOENT, no such file or directory '/node_modules/request/node_modules/mime/types/mime.types' W20160302-09:47:50.954(1)? (STDERR) at Object.fs.openSync (fs.js:439:18) W20160302-09:47:50.955(1)? (STDERR) at Object.fs.readFileSync (fs.js:290:15) W20160302-09:47:50.955(1)? (STDERR) at Mime.load (node_modules/request/node_modules/mime/mime.js:47:1)

Searching the file with an absolute path, obviously not there.

Request uses fs , so it would seem that the issue is between fs and the request module. but since request is widely used, could it be Meteor related?

I have the same kind of problem when I setup a package using node-bitlyapi (which uses request) and run meteor test-packages my_package

W20160612-14:50:34.727(2)? (STDERR)
W20160612-14:50:34.727(2)? (STDERR) /Users/laurent/.meteor/packages/meteor-tool/.1.3.2_4.lbyo5v++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:267
W20160612-14:50:34.727(2)? (STDERR) throw(ex);
W20160612-14:50:34.727(2)? (STDERR) ^
W20160612-14:50:34.774(2)? (STDERR) Error: ENOENT, no such file or directory '/node_modules/meteor/my_package/node_modules/node-bitlyapi/node_modules/request/node_modules/mime/types/mime.types’
W20160612-14:50:34.774(2)? (STDERR) at Object.fs.openSync (fs.js:439:18)
W20160612-14:50:34.774(2)? (STDERR) at Object.fs.readFileSync (fs.js:290:15)
W20160612-14:50:34.775(2)? (STDERR) at Mime.load (node_modules/meteor/my_package/node_modules/node-bitlyapi/node_modules/request/node_modules/mime/mime.js:54:1)
W20160612-14:50:34.775(2)? (STDERR) at meteorInstall.node_modules.meteor.bitlyapi.node_modules.node-bitlyapi.node_modules.request.node_modules.mime.mime.js (node_modules/meteor/my_package/node_modules/node-bitlyapi/node_modules/request/node_modules/mime/mime.js:90:1)
W20160612-14:50:34.775(2)? (STDERR) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:141:1)
W20160612-14:50:34.775(2)? (STDERR) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:75:1)
W20160612-14:50:34.775(2)? (STDERR) at meteorInstall.node_modules.meteor.bitlyapi.node_modules.node-bitlyapi.node_modules.request.request.js (node_modules/meteor/my_package/node_modules/node-bitlyapi/node_modules/request/request.js:17:1)
W20160612-14:50:34.775(2)? (STDERR) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:141:1)
W20160612-14:50:34.775(2)? (STDERR) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:75:1)
W20160612-14:50:34.776(2)? (STDERR) at meteorInstall.node_modules.meteor.my_package.node_modules.node-bitlyapi.node_modules.request.index.js (node_modules/meteor/my_package/node_modules/node-bitlyapi/node_modules/request/index.js:17:1)
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.

This path is not good

> /node_modules/meteor/my_package/node_modules/node-bitlyapi/node_modules/request/node_modules/mime/types/mime.types

At mime.js:90 

> mime.load(path.join(__dirname, 'types/mime.types'));

__dirname gives "The name of the directory that the currently executing script resides in"= meteor path ?

TEMPORARY SOLVED with [direction given until correction published]( 

> // import BitlyAPI from 'node-bitlyapi';       // commented
var BitlyAPI = Npm.require('node-bitlyapi');  // replaced by Npm.required

I’m really skeptical when using packages which magically wrap async. I prefer to manually wrap async, or write your own fibers since then you know exactly what’s happening. All of my problems with stuff like this have been solved by manually just wrapping code. I’ve run into some sticky issues with Meteor’s HTTP… It seems that Node.js changed how they implemented buffers, and the current version of HTTP apparently isn’t equipped to handle that. I was gonna post a bug in Meteor’s github issues but then they were asking me to write a book, so I forgot about it.

//using basic, built-in, pre-loaded vanilla node `http` module.
function downloadSync(url){
  let f = Fiber.current;
  http.get(url, function(e, res){
    if (e){f.throwInto(e)};
    let d = new Buffer([]); //don't do d = '', and d += bit;
    res.on('data', function(bit){
      d = Buffer.concat(d, bit)
    res.on('end', function(){;
let task = new Fiber(function(){
  let url = getUrlFromSomewhere();
  let data = downloadSync(url)
  console.log(data) // <Buffer 0f 03 ff ...>