2

我是 node.js 的初学者。我想连接 API 进行培训。我是公司代理的幕后黑手。我有一个 api 密钥:http ://numbersapi.com/2000/math?json并且我想通过 node-fetch 进行连接,但我在控制台中收到错误消息:

Error:  { FetchError: request to http://numbersapi.com/2000/math failed, reason: connect ECONNREFUSED 107.170.248.47:80
    at ClientRequest.<anonymous> (C:\user\training\Node.js\number_API\node_modules\node-fetch\lib\index.js:1455:11)
    at ClientRequest.emit (events.js:193:13)
    at Socket.socketErrorListener (_http_client.js:397:9)
    at Socket.emit (events.js:193:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:17)
  message:
   'request to http://numbersapi.com/2000/math failed, reason: connect ECONNREFUSED 107.170.248.47:80',
  type: 'system',
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED' }

我在 .npmrc 中设置了属性:

proxy=http://xxx.xxx.com:8080
https-proxy=http://xxx.xxx.com:8080
registry=https://registry.npmjs.org
4

1 回答 1

0

据我所知,node-fetch 不尊重环境变量或 .npmrc 中定义的任何内容。您需要明确定义代理。

于 2020-02-04T18:53:02.927 回答