简体   繁体   中英

request module doesn't callback after browserify

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM