Skip to content

Instantly share code, notes, and snippets.

@alifrizkip
Last active February 7, 2018 08:50
Show Gist options
  • Save alifrizkip/eb54ec3fc257116342067f97021a1bfe to your computer and use it in GitHub Desktop.
Save alifrizkip/eb54ec3fc257116342067f97021a1bfe to your computer and use it in GitHub Desktop.
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