node.js - 将 Excel 转换为 SQL,然后转换为 JSON,以优化在 NodeJS 中发送到客户端的数据响应
问题描述
我有一个应用程序,我们使用此方法上传包含数据的 Excel 文件:
// Upload and replace excel file for a new version of the excel file
app.post('/data', function (req, res) {
const upload = multer({ storage }).single('document');
fs.unlink(path2, (err) => {
if (err) {
console.error(err)
return
}
upload(req, res, function (err) {
if (err) {
return res.end("error lors de upload")
}
res.redirect('/')
})
})
});
然后还有另一种方法,将excel转成JSON,将数据发送给客户端:
// Converts Excel to JSON and send to client
app.get('/json2', (req, res) => {
node_xj({
input: "uploads/data.xlsx",
output: "output.json"
}, function (err, result) {
if (err) {
console.error(err);
} else {
const interval = setInterval(() => {
console.log('test')
}, 3600 * 24 * 365)
res.send(result);
console.log("results send ok");
}
});
})
但是这个过程比较慢,因为每次客户端请求数据,服务器都要将excel转成JSON再发送数据,所以有时候客户端收不到数据。
我想知道是否可以通过将 Excel 数据放入 SQL 中,然后 json2 路由将 SQL 转换为 JSON 并发送到客户端来使用脚本对此进行优化。
我的 nodejs 应用程序现在部署在 Heroku 中。
你知道怎么做吗?你能给点建议吗?
提前致谢
解决方案
推荐阅读
- c# - 在列表中查找缺失的必需值
- r - tikzDevice 在 RMarkdown 文档中使用时不使用 LaTeX 前导码
- haskell - 让 putStrLn 在 if-else 块中工作
- php - 当用户单击 PHP 中的某个用户名时,如何查看帐户的不同配置文件?
- gams-math - 如何在向量(参数)中找到?
- javascript - 如何将数据保存在本地存储中?
- c# - 谷歌日历 API 定期事件(按小时)
- html - 为什么当浏览器大小改变时我的列不调整大小
- python - 将计划信息(开始和结束时间)拆分为更小的间隔
- asp.net-mvc - 单击按钮时未选择 Casecading 下拉列表