js-xlsx을 사용하여 Node.js 서버에서 Excel 파일을 읽습니다. 파일은 다중 부분 양식 데이터를 사용하여 게시되며 임시 위치에 저장됩니다. 그러나 파일을 읽는 동안 내 Node.js 스레드가 차단되어 다른 요청을 처리 할 수없는 것처럼 보입니다. 다음 코드에서 /에 대한 호출이 보류 중일 때 /를 호출하면 /가 호출 될 때까지 호출이 완료 될 때까지 기다립니다.Node.js에서 js-xlsx를 사용하여 비 차단 읽기
const express = require('express');
var XLSX = require('xlsx');
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.get('/read', function (req, res) {
console.log("Starting file read ...");
var workbook = XLSX.readFile("/tmp/myfile.xlsx")
console.log("Done file read ...");
res.send('File Read')
})
app.get('/readwithtimeout', function (req, res) {
console.log("Starting file read ...");
setTimeout(function() {
var workbook = XLSX.readFile("/tmp/myfile.xlsx")
console.log("Done file read ...");
}, 0);
res.send('File Read')
})
app.listen(3000, function() {
console.log('Example app listening on port 3000!')
})
Excel 파일을 읽고 구문 분석하는 올바른 방법입니까? 아니면 다른 일을해야합니까? 여기에 자신의 문서에 따르면
그 중 하나가 도움이되지 않는다고 생각합니다. 이제 브라우저에서 파일을 구문 분석하고 Node.js 서버의 구문 분석 된 데이터를 다시 보내 데이터베이스에 대량로드를 수행하는 것이 적절한 해결책이라고 생각합니다. –