Last active
February 7, 2018 08:50
-
-
Save alifrizkip/eb54ec3fc257116342067f97021a1bfe to your computer and use it in GitHub Desktop.
index.js for https://github.com/alfrizp/nodejs-import-csv-to-db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const csv = require('csvjson') | |
const knex = require('./knex') | |
const fs = require('fs') | |
const file = fs.readFileSync('data.csv', 'utf8') | |
const dataObj = csv.toObject(file) | |
knex.insert(dataObj) | |
.into('employees') | |
.then(() => { | |
console.log('Import data done!') | |
process.exit(0) | |
}) | |
.catch(() => { | |
console.log('Import data failed') | |
process.exit(0) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment