“cara membaca file csv di nodeJS” Kode Jawaban

Baca dan Perbarui File CSV Di 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
    })
Better Bug

Buat NodeJs File CSV

const csv = require('csv-parser');
const fs = require('fs');

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (row) => {
    console.log(row);
  })
  .on('end', () => {
    console.log('CSV file successfully processed');
  });
Suspect Camel

cara membaca file csv di nodeJS

$ npm i -s csv-parse
Busy Badger

Jawaban yang mirip dengan “cara membaca file csv di nodeJS”

Pertanyaan yang mirip dengan “cara membaca file csv di nodeJS”

Lebih banyak jawaban terkait untuk “cara membaca file csv di nodeJS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya