Giter Site home page Giter Site logo

node-csv-parser-demo's Introduction

node-csv-parser-demo

Demo app to parse CSV files in Node.js

CSV to NDJSON

Using csv-parser one can easily convert CSV to NDJSON. A script csv-to-json.sh was written to test it out. It can be executed by passing a single file as (-f) argument or all CSV files inside a directory by passing (-d) argument.

File

$ docker-compose run --rm cli bash
#./csv-to-json.sh -f data/posts.csv
Generated data/posts.json

Directory

$ docker-compose run --rm cli bash
#./csv-to-json.sh -d ./data
Generated ./data/groups.json
Generated ./data/posts.json

CSV import to MongoDB

In many cases we may want to import CSV data to a database. As an example we can parse CSV data and import it to a MongoDB database as follows:

$ docker-compose up -d
$ docker-compose run --rm cli bash
# node import-data.js data/posts.csv
Established database connection
CSV file successfully processed
Pipeline succeeded
New row created for import id: 15887
New row created for import id: 15421
New row created for import id: 15461
Closed database connection

Verify that the rows were imported:

$ docker-compose exec db bash
# mongo -u root -p pass
> show dbs
admin     0.000GB
cli_demo  0.000GB
config    0.000GB
local     0.000GB

> use cli_demo
switched to db cli_demo

> show collections
posts

> db.posts.count()
3

node-csv-parser-demo's People

Contributors

jahangiranwari avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.