Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
How to convert the JSON file as a response to my own server

I have this code to convert Excel file to JSON format and it gave a JSON file, may I know how to convert this as a response? I tried using res.send the js code as usual but it gave the directory/inner codes instead. Please help

    let express = require('express');
    let server = express();
    let upload = require('express-fileupload');
    let importExcel = require('convert-excel-to-json');
    
    server.use(upload());
    
    server.get('/', (req, res)=> {
        res.sendFile(__dirname+'/index.html');
    });
    
    server.post('/', (req, res)=>{
        let file = req.files.filename;
        let filename = file.name;
        file.mv('./excel/'+filename,(err)=>{
            if (err){
                res.send('fail');
            }else{
                let result = importExcel({
                    sourceFile : './excel/'+filename
                });
            }
        });
    }); 
    
    
    server.listen(9000,()=> {console.log('Server listen to port 9000')});

This is another js file to convert excel --> JSON

const xlsx = require('xlsx'); var fs = require('fs'); const { json } = require('express');

function convertExcelFileToJsonUsingXlsx() {
    const file = xlsx.readFile('./excel/Book1.xlsx');

    const sheetNames = file.SheetNames;
    
    let parsedData = [];

    const testData = xlsx.utils.sheet_to_json(file.Sheets[sheetNames]);
    parsedData.push(...testData);

    generateJSONFile(parsedData); }

function generateJSONFile(data) {
    try {
        fs.writeFileSync('data.json', JSON.stringify(data))
    } catch (err) {
        console.error(err)
    } }

but instead of giving out as a JSON file, I want to convert the JSON as a response to my server using

server.get('/json', (req, res) {
        res.setHeader('Content-Type', 'text/html; charset=utf-8');
        res.send('');});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems like you're using express, as you mentioned res.

const json = require('path_to_json.json')

app.get('...', (req, res) => {
    // ...

    res.send(JSON.stringify(json));
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!