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

100
Views
create json object from csv file data coming as buffer in request in node js

I'm processing csv file data coming from request to create json object using multer,csv-parser. but can't process from long time. please help and thanks.following is example of csv file processing.

const multer = require('multer');
const fs = require('fs')
const csv =  require('csv-parser')
const fileStorageEngine = multer.memoryStorage({
  destination: (req, file, cb) => {
    cb(null, './csv');
  }
  ,
  filename: (req, file, cb) => {
    cb(null, file.originalname);
  },
});
const upload = multer({storage:fileStorageEngine});
app.post('/uploadcsv',upload.single("upfile"),async(req,res)=>{
const file = req.file;
fs.createReadStream(`./csv/${file.originalname}`)
.pipe(csv())
.on("data",(data)=>console.log(data));
res.send("file uploaded")
})

here I'm using fs module that works for me but I don't want to store data in file instead I want to process buffer data coming from req.file.buffer in chunk I'm stuck here please help. because storing file and reading same file getting process slow because csv file have thousands of data.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The idea is to create a readable stream from the buffer instead of writing it to the file as follows:

const multer = require('multer');
const { Readable } = require('stream');
const fs = require('fs')
const csv =  require('csv-parser')
const fileStorageEngine = multer.memoryStorage({
  destination: (req, file, cb) => {
    cb(null, './csv');
  }
  ,
  filename: (req, file, cb) => {
    cb(null, file.originalname);
  },
});
const upload = multer({storage:fileStorageEngine});
app.post('/uploadcsv',upload.single("upfile"),async(req,res)=>{
const file = req.file;

const stream = Readable.from(file.buffer);

stream.pipe(csv()).on("data",(data)=>console.log(data));
res.send("file uploaded")
})
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!