Socket
Socket
Sign inDemoInstall

csv-writer

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-writer

Convert objects/arrays into a CSV string or write them into a CSV file


Version published
Weekly downloads
585K
increased by1.29%
Maintainers
1
Weekly downloads
 
Created

What is csv-writer?

The csv-writer npm package is a simple and powerful library for writing CSV files in Node.js. It provides an easy-to-use API for creating CSV files from arrays of objects or arrays of arrays, and it supports various customization options such as headers, field delimiters, and encoding.

What are csv-writer's main functionalities?

Writing CSV from an array of objects

This feature allows you to write a CSV file from an array of objects. You can specify the path to the output file and define the headers for the CSV file. The records are written to the CSV file, and a promise is returned to indicate when the writing is complete.

const createCsvWriter = require('csv-writer').createObjectCsvWriter;

const csvWriter = createCsvWriter({
  path: 'out.csv',
  header: [
    {id: 'name', title: 'NAME'},
    {id: 'age', title: 'AGE'},
    {id: 'address', title: 'ADDRESS'}
  ]
});

const records = [
  {name: 'John Doe', age: 30, address: '123 Main St'},
  {name: 'Jane Doe', age: 25, address: '456 Maple Ave'}
];

csvWriter.writeRecords(records)       // returns a promise
  .then(() => {
    console.log('...Done');
  });

Writing CSV from an array of arrays

This feature allows you to write a CSV file from an array of arrays. You can specify the path to the output file and define the headers for the CSV file. The records are written to the CSV file, and a promise is returned to indicate when the writing is complete.

const createCsvWriter = require('csv-writer').createArrayCsvWriter;

const csvWriter = createCsvWriter({
  path: 'out.csv',
  header: ['NAME', 'AGE', 'ADDRESS']
});

const records = [
  ['John Doe', 30, '123 Main St'],
  ['Jane Doe', 25, '456 Maple Ave']
];

csvWriter.writeRecords(records)       // returns a promise
  .then(() => {
    console.log('...Done');
  });

Customizing field delimiters

This feature allows you to customize the field delimiter used in the CSV file. In this example, the field delimiter is set to a semicolon (';'). The records are written to the CSV file with the specified delimiter, and a promise is returned to indicate when the writing is complete.

const createCsvWriter = require('csv-writer').createObjectCsvWriter;

const csvWriter = createCsvWriter({
  path: 'out.csv',
  header: [
    {id: 'name', title: 'NAME'},
    {id: 'age', title: 'AGE'},
    {id: 'address', title: 'ADDRESS'}
  ],
  fieldDelimiter: ';'
});

const records = [
  {name: 'John Doe', age: 30, address: '123 Main St'},
  {name: 'Jane Doe', age: 25, address: '456 Maple Ave'}
];

csvWriter.writeRecords(records)       // returns a promise
  .then(() => {
    console.log('...Done');
  });

Other packages similar to csv-writer

Keywords

FAQs

Package last updated on 06 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc