I had an excel file that I managed to read in the NodeJS, here is the excel format:
I have no header, only 4 columns. And the code I used is the following:
const { Client } = require("pg");
const xlsx = require("node-xlsx");
var data = xlsx.parse(__dirname + "/disease_data.xlsx");
var diseaseCode = [];
var disease = [];
var symptomCode = [];
var symptom = [];
const client = new Client({
host: "localhost",
user: "postgres",
port: 5432,
password: "dizertatie",
database: "SymptomChecker",
});
client.connect();
for (var i = 0; i < data.length; i++) {
var sheet = data[i];
console.log(sheet["data"][i][1]);
for (var j = 0; j < sheet["data"].length; j++) {
//add the row to the rows array
// diseaseCode.push(sheet["data"][j][0]);
//Here is the problem
client.query(`INSERT INTO diseases (diseaseCode, disease, symptomCode, symptom) VALUES ('${}')`)
}
}
The problem is, I managed to stack each column from the excel into different arrays, but I don't know to push them corresponding line by line. What can I do?