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

193
Views
Merge multipesCSV into one javascript node.js

Someone could help me ? I have to merge multiples csv files into one single csv file.

The csv files have the same header.

I'm using node.js and javascript.

Thank you

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

0

Some basic string manipulation will do well.

const fs = require("fs");
const path = require("path");

// get paths to file
const file1 = path.join(__dirname, "path/to/file1.csv"),
  file2 = path.join(__dirname, "path/to/file2.csv");

// read the csv files
const csv1 = fs.readFileSync(file1),
  csv2 = fs.readFileSync(file2);

// split the second csv by a new line then remove the first line (remove the header)
const [, ...rest] = csv2.split("\n");
const result = csv1 + rest.join("\n"); // combine csv

fs.writeFileSync(path.join(__dirname, "output.csv"), result); // write result to file

You can also do this dynamically:

// let's pretend you have an array of all the CSV text that you read from the file system named 'csv'
for(let i = 1; i < csv.length; i++) {
  const [, ...spl] = csv[i].split("\n");
  // instead of doing [, ...spl] we could also call: spl.shift();
  csv[i] = spl.join("\n");
}

const result = csv.join("\n"); // our combined csv
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!