gpt4 book ai didi

node.js - 将Node包与Electron一起使用会给我返回 `ERR_CONNECTION_REFUSED`

转载 作者:行者123 更新时间:2023-12-03 12:35:05 25 4
gpt4 key购买 nike

所以我正在尝试制作一个像 Electron 书那样的pokedex应用程序,为此,我需要使用this api,而this one的 Node 版本是这样。

我的问题是,当我尝试使用api时,我的控制台只将ERR_CONNECTION_REFUSED返回给我:

// basic setup
var Pokedex = require('pokedex-promise-v2');
var options = {
protocol: 'https',
hostName: 'localhost:443',
versionPath: '/api/v2/',
cacheLimit: 100 * 1000, // 100s
timeout: 5 * 1000 // 5s
}
var P = new Pokedex(options);

// get a berry by name
P.getBerryByName('cheri')
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log('There was an ERROR: ', error);
});

这是我的控制台返回我的内容:
Failed to load resource: net::ERR_CONNECTION_REFUSED
base.js:26 There was an ERROR: Error: Network Error
at createError (D:\Documents\_Dev\Pokecheck\node_modules\axios\lib\core\createError.js:16)
at XMLHttpRequest.handleError (D:\Documents\_Dev\Pokecheck\node_modules\axios\lib\adapters\xhr.js:87)

我也尝试过使用json文件的网址(例如: https://pokeapi.co/api/v2/pokemon/1/),但是在集成时会破坏我的应用程序...

最佳答案

var options = {
protocol: 'https',
hostName: 'pokeapi.co',
versionPath: '/api/v2/',
cacheLimit: 100 * 1000, // 100s
timeout: 5 * 1000 // 5s
}

我假设您不在本地计算机上运行API。因此,向本地主机询问未运行的内容将导致 ERR_CONNECTION_REFUSED

如果您不解析选项对象,则Pokedex具有默认选项,该选项对象已经设置好您将如何使用它。

因此,基本上,您只需要不带该选项的 var P = new Pokedex();

关于node.js - 将Node包与Electron一起使用会给我返回 `ERR_CONNECTION_REFUSED`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53742744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com