Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Unbale使用fetch发送请求_Node.js_Fetch - Fatal编程技术网

Node.js Unbale使用fetch发送请求

Node.js Unbale使用fetch发送请求,node.js,fetch,Node.js,Fetch,我正在使用fetch发送http请求这是我的代码: const fetch = require('fetch') fetch('https://api.github.com/users/github') .then(res => res.json()) .then(json => console.log(json)); 然而,我得到了这个错误: TypeError:fetch不是一个函数 感谢您的指导,谢谢 删除此行 const fetch=require('fe

我正在使用fetch发送http请求这是我的代码:

const fetch = require('fetch')

fetch('https://api.github.com/users/github')
    .then(res => res.json())
    .then(json => console.log(json));
然而,我得到了这个错误:

TypeError:fetch不是一个函数

感谢您的指导,谢谢

删除此行

const fetch=require('fetch')

删除此行


const fetch=require('fetch')

fetch在Node JS中不可用,您必须使用Node fetch

然后像这样要求它:

const fetch = require('node-fetch');

Fetch在Node JS中不可用,您必须使用Node Fetch

然后像这样要求它:

const fetch = require('node-fetch');
是的,使用“节点获取”

还可以尝试切换到异步等待;从语法上讲要好得多——因为node fetch返回承诺,您已经知道:)

是的,使用“节点获取”

还可以尝试切换到异步等待;从语法上讲要好得多——因为node fetch返回承诺,您已经知道:)


删除该行不会发生任何事情。Node没有fetch,您必须从npm使用Node fetch。删除该行不会发生任何事情。节点没有fetch,您必须从npm使用节点fetch。