黑白梦黑白梦

  • 文章
  • 专栏
  • 文章
  • 专栏
全部文章

Node.js 中的同步的 http 请求库 sync-request

发布于 2022-07-13更新于 2023-07-30约 1 分钟

关于

https://github.com/ForbesLindesay/sync-request

在一些场景下,比如在 webpack 、next.config.js 这种配置文件中,如需请求数据,异步的模式下往往不好写。

sync-request 可以写出同步的代码,让 node.js 暂停直到请求完毕。

使用方法

npm install sync-request -D

示例:

var request = require('sync-request');
var res = request('GET', 'http://example.com');
console.log(res.getBody());

因同步模式性能不佳,官方强调:不能使用在生产环境。但它有非常独特的使用场景。

目录
关于使用方法

本文收录于专栏

一些好用的 npm 前端开源库

收集一些好用的前端开源库,主要是 npm 包

0 篇文章更新于 2026-08-17
上一篇ffmpeg.wasm 浏览器中的 ffmpeg下一篇why did you render 排查 react 渲染情况

©2015-2026 黑白梦 粤ICP备15018165号

联系: heibaimeng@foxmail.com