我试图在终端上使用npm start运行这段代码
//index.js
const api = require('./api');
console.log('Iniciando monitoramento!');
setInterval(async () => {
//console.log(await api.time());
console.log(await api.depth());
}, process.env.CRAWLER_INTERVAL);//api.js
const axios = require('axios');
const queryString = require('querystring');
async function publicCall(path, data, method = 'GET', headers = {}) {
try {
const qs = data ? `?${queryString.stringify(data)}` : '';
const result = await axios({
method,
url: `${process.env.API_URL}${path}${qs}`
});
return result.data;
} catch (err) {
console.error(err);
}
}
async function time() {
return publicCall('/v3/time');
}
async function depth(symbol = 'BTCBRL', limit = 5) {
return publicCall('/v3/depth', { symbol, limit });
}我的终端显示了这个错误:
console.log(await api.depth());
^
TypeError: api.depth is not a function
at Timeout._onTimeout (C:\Users\mikae\Desktop\bot-criptomoedas\bot\index.js:6:27)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)我只想运行我的应用程序寄给我有关密码硬币市场的信息。我在使用宾斯的API。
发布于 2021-06-06 18:33:28
您需要导出函数。
export async function depth(symbol = 'BTCBRL', limit = 5) {
return publicCall('/v3/depth', { symbol, limit });
}然后
import { depth } from '/.api'还可以更新您的package.json文件以包括。
"type": "module"
发布于 2021-06-06 18:56:51
在您所链接的教程中,您忽略了第25行:
module.exports = { time, depth }将其粘贴到您的app.js文件中,并在index.js中用作导入
const api = require('./api.js');https://stackoverflow.com/questions/67861620
复制相似问题