Answers for "read and update csv file in nodejs"

0

read and update csv file in nodejs

const fs = require('fs')
const csv = require('csv-parser')
const randomWords = require('random-words')
const users = [];
function generateUsername(firstname, surname) {
    return `${firstname[0]}-${surname}`.toLowerCase();
}
fs.createReadStream('input.csv')
  .pipe(csv())
  .on('data', function (row) {
    const username = generateUsername(row.Firstname, row.Surname);
    const password = randomWords(3).join("-");
    
    const user = {
        username,
        firstname: row.Firstname,
        surname: row.Surname,
        roles: row.Roles,
        password
    }
    users.push(user)
  })
  .on('end', function () {
      console.table(users)
      // TODO: SAVE users data to another file
    })
Posted by: Guest on June-22-2021
3

how to read a csv file in nodejs

$ npm i -s csv-parser
Posted by: Guest on December-22-2020
1

how to read a csv file in nodejs

$ npm i -s csv-parse
Posted by: Guest on December-22-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language