Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karliatto/csv-parser-nodejs-cli
A CLI with nodeJS for parsing csv files
https://github.com/karliatto/csv-parser-nodejs-cli
cli csv javascript nodejs
Last synced: 29 days ago
JSON representation
A CLI with nodeJS for parsing csv files
- Host: GitHub
- URL: https://github.com/karliatto/csv-parser-nodejs-cli
- Owner: karliatto
- Created: 2017-04-18T19:39:47.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-14T15:43:19.000Z (over 7 years ago)
- Last Synced: 2024-10-30T18:48:26.227Z (3 months ago)
- Topics: cli, csv, javascript, nodejs
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A CLI with [nodeJS](https://nodejs.org/)
## Create a git repository
```bash
git init
```## Create a package.json file
```bash
npm init
```
## Create a new file: hello-world.js
```javascriptconsole.log('hello world');
```
## Install [commanderjs](https://github.com/tj/commander.js)
```bash
npm install commander --save
```
```javascript
var program = require('commander');program
.version('0.0.1')
.option('-l, --list [list]', 'List of customers in CSV')
.parse(process.argv)
``````bash
node hello-world --list 'hello world'
node hello-world --version
node hello-world --help```
## Install [node-csv](https://github.com/wdavidw/node-csv)
```bash
npm install csv --save
``````javascript
var csv = require('csv');
var fs = require('fs');var parse = csv.parse;
var stream = fs.createReadStream(program.list)
.pipe(parse({ delimiter : ',' }));stream
.on('data', function (data) {
var firstname = data[0];
var lastname = data[1];
var email = data[2];
console.log(firstname, lastname, email);
})
``````bash
node hello-world --list people.csv
```## Improving the output
```bash
npm install chalk --save
``````javascript
.on('end', function() {
console.log(chalk.green('success'));
})
```## Finally doing a bash command
[Shebang/Hasbang](https://en.wikipedia.org/wiki/Shebang_(Unix)) Under Unix-like operating systems, when a script with a shebang is run as a program.
- Add shebang at the top of the file
```
#!/usr/bin/env node
``````javascript
"bin": {
"hello-world": "./hello-world.js"
}
``````bash
sudo npm install -g
```