node 上使用fetch
1. 下载(要在你的.js文件的目录下)
npm install node-fetch
2.引用
const fetch = require("node-fetch");
3.全部
const fetch = require("node-fetch");
fetch(url)
.then(data => data.json())
.then(data => console.log(data));
const fetch = require("node-fetch");
(async () => {
try {
let response = await fetch(url);
let data =await response.json();
console.log(data);
} catch (e) {
console.log("Oops, error", e);
}
})()