I'm trying to download a .xlsx file from a ftp, and converting it to a .json using XSLX module, and then writing it to a file. All this using Node.js
const fs = require('fs');
const Client = require('ftp');
const XLSX = require('xlsx');
const c = new Client();
c.connect({
host: '***.***.***.**',
user: '*********',
password: '*********',
});
c.on('ready', () => {
c.get('/market.xlsx', (err, stream) => {
if (err) throw err;
stream.once('close', () => c.end());
let content = '';
stream.on('data', (chunk) => {
content += chunk;
});
stream.on('end', () => {
//I guess something is wrong here
const json = XLSX.utils.sheet_to_json(content);
fs.writeFileSync(
'./files/market-to-json.json',
JSON.stringify(json, null, 2),
'utf-8'
);
});
});
});
My actual output in .json
[]
I struggled with this for a week and can't find solution, please help!.