在前端使用 node.js 个库

Using node.js libraries on front-end

如何在前端使用'request'node.js模块?

通常我会像这样检索它:

var request = require('request');

但这在前端是不可能的,因为无法识别 require。

解决这个问题的最佳方法是什么?

要在浏览器中使用节点模块,您可以使用名为 Browserify . This allows you to work with the common module pattern as well as the you can use this package browser-request 的库来获取请求模块的功能