nodejs 如何使用 fetch

node 中没有实现 fetch,你可以使用 node-fetch,使得在 node 中也可以使用 fetch.

安装 node-fetch:

npm install node-fetch

使用 fetch 之前先加载:

const fetch = require('node-fetch')

简单使用方法:

fetch('https://api.github.com/users/github')
    .then(res => res.json())
    .then(json => console.log(json));

关于 fetch 的使用介绍 https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

猜你喜欢

转载自blog.csdn.net/henryhu712/article/details/87775497