Frage

I'm trying to use the 'request' npm module in a client side lib with browserify but I'm having trouble.

The code I have is pretty standard, I'm posting a request to the server from the browserified version with something like:

request.post("/comments", { json: self }, function(err, resp, body) {
  // ... handle response here ...
});

but I'm not getting called back from request even though I see that the request is successful in the network tab of Chrome. Has anyone seen this before? Do I need to substitute a client version of 'request' for the node.js one?

War es hilfreich?

Lösung

request has quite a few dependencies, and when I try and browserify it, I get a version of the following:

Error: module "dns" not found from "node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js"

I'd suggest one of the following:

  • browser-request - port of request for the browser.
  • hyperquest - streaming http requests. Not the full api that request provides, but it's lighter weight. It won't parse response bodies for you though, which I'm guessing you want.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top