我知道这与针对相同错误提出的其他问题非常相似。在我看到的情况下,该文件名已从URL中删除。就我而言(据我所知),URL已按原样指定,并且可以使用其他工具在本地主机上查看该文件。
我需要在node.js应用中对json文件执行I / O,而无需使用快速路由。这是一个只有一个路由的API(processor.js)。通过选择“处理”在GUI上的菜单选择可以访问它。从那时起,该路由中发生的一切都包括到json的多个GET / PUT(将id转换为数据,然后使用id来获取数据),以及构建SQL行以从解析的json数据填充SQL-Server表。那至少是我现在正在测试的概念。这是我的牌,所以我没有其他选择。
我使用的是fs-extra而不是request或axios等,因为它们似乎都希望通过快速路由来完成I / O。我似乎能够使用fs-extra直接读取和写入json。我在SQL端使用sequelize(或将要使用)。
那是背景。
这是我的processor.js(我只是在验证此时我是否可以将idsList返回给我):
if(db.open())
{
// Insert Query
QSqlQuery query(QSqlDatabase::database("MyConnection"));
query.prepare("SELECT * FROM users WHERE email = :email AND password = :password");
query.bindValue(":email", email);
query.bindValue(":password", password);
if(!query.exec())
{
QMessageBox::information(this,"Failed","Error please try again");
}
else
{
while(query.next())
{
QString emailLog = query.value(1).toString();
QString passwordLog = query.value(4).toString();
if(emailLog == email && passwordLog == password){
QMessageBox::information(this,"SUCCESS","SUCCESS");
db.close();
}
else
{
ui->plstryagain->show();
db.close();
}
}
}
}
else
{
QMessageBox::information(this, "Database Error", "Can't Connect To Database");
}
}
这是我的getIds函数:
'use strict';
// node_modules
const express = require('express');
const router = express.Router();
const fse = require('fs-extra')
// local modules
const idsList = require('../functions/getIds');
router.get('/', (req, res) => {
console.log(idsList);
});
module.exports = router;
这是我的错误,输出到控制台(格式不正确):
'use strict';
// library modules
const express = require('express');
const router = express.Router();
const fse = require('fs-extra');
const uri = require('../uri');
// initialize general variables
let baseURL = `http://localhost:5000${uri}/`;
let idsID = 'ids.json';
const getIds = async () => {
let url = `${baseURL}${idsID}`;
try {
const idsList = await fse.readJson(url);
console.log('fse.readJson',idsList);
} catch (err) {
console.error(err);
}
}
module.exports = getIds();
'http://localhost:5000/Users/doug5solas/sandbox/libertyMutual/playground/api/ids.json'] errno:-2, 代码:“ ENOENT”, syscall:“打开”, 路径: 'http://localhost:5000/Users/doug5solas/sandbox/libertyMutual/playground/api/ids.json'
我想念什么?
答案 0 :(得分:1)
fs-extra
来操作本地文件系统中的文件和目录。axios
之类的http客户端。答案 1 :(得分:0)
我从fs-extra移到了fs.readFileSync并解决了问题。这不是我的偏爱。但是它确实可以工作并且文件很小,只有一次。