csv-to-db
v1.0.4
Published
csv-to-db-testpackage
Downloads
2
Readme
csv-to-db
Bulk insert csv file to table.
Supported file type:
- csv
Installation
npm i csv-to-db
Example usage
const csvtodb = require('csv-to-db');
const express = require("express");
const app = express.Router();
app.post('/upload', async (req, res) => {
const file = req.files.file;
const upload_file = req.files.file;
const data = csvtodb.csvtodbinsertion({ hostname, username, password }, { dbname }, { tablename },upload_file)
return res.status(200).json({
data
});
})
Here csvtodbinsertion is the main function that do all work for you.
It accepts four paramters
- object that include your dbhost details like
- hostname
- host username
- host password
- db name
- table name
- file
NOTE
Your csv file must contain columns as first row and then values in other rows | Column1 | Column2 | Column3 | | :---: | :---: | :---: | | Value11 | Value12 | Value13 | | Value21 | Value22 | Value23 |