CSVStringify for Node.js

IssuesGitHub

ECMAScript modules (ESM) for newer browsers

The ESM distribution target the latest browsers with support for ECMAScript modules introduced by ES6 introduced by ES6.

Compared with the Node.js version, this distribution bundles polyfills to run outside of the Node.js environment.

Additional information are available in the project ECMAScript modules documentation.

Usage

The files can be manually imported. They dont require any external dependencies and they are located inside the packages/csv-stringify/dist/esm folder.

When using NPM to manage and load your modules, for example within webpack, use:

import {stringify} from 'csv-stringify/browser/esm';
// Or
import {stringify} from 'csv-stringify/browser/esm/sync';

Vanilla JavaScript

A working demo is available in the project demo/browser directory.

With Express, expose the files with:

const app = express();
app.use('/lib/stringify/',
  express.static(`node_modules/csv-stringify/dist/esm/`));
app.listen(3000);

The HTML code looks like:

<script type="module">
  import {stringify} from '/lib/stringify/index.js';
  stringify(records, options, (err, data) => {
    console.info(data)
  });
</script>

If you wish to use the sync API, use:

<script type="module">
  import {stringify} from '/lib/stringify/sync.js';
  const data = stringify(records, options);
</script>

Webpack module bundler

This distribution is compatible with webpack version 5. It comes with the Node.js polyfills. A working demo is shared on the project repository.

In your module, import the appropriate csv-stringify module:

The relevant webpack configuration looks like:

  {
    entry: './src/stringify.js',
    mode: 'development',
    output: {
      filename: 'stringify.js',
      path: path.resolve(__dirname, 'dist'),
    }
  },
  {
    entry: './src/stringify_sync.js',
    mode: 'development',
    output: {
      filename: 'stringify_sync.js',
      path: path.resolve(__dirname, 'dist'),
    }
  },

About

The Node.js CSV project is an open source product hosted on GitHub and developed by Adaltas.