The Excel file is a spreadsheet file format created by Microsoft for use with Microsoft Excel. You can use the file to create, view, edit, analyse data, charts, budgets and more. In this tutorial, I will show you how to upload & read Excel file in Node.js then save data into MySQL Database.
Full Article: https://bezkoder.com/node-js-upload-excel-file-database/
Node.js Upload & read Excel File Rest APIs
Assume that we have an .xlsx file that contains Tutorial data in Tutorials sheet as following:
We're gonna create a Node.js Application that provides APIs for:
- uploading Excel File to the Node.js Express Server & storing data in MySQL Database
- getting list of items from MySQL table
- downloading MySQL table data as Excel file
After the Excel file is uploaded and read successfully, tutorials table in MySQL database will look like this:
If we get list of Tutorials, the Node.js Rest Apis will return:
For more details, implementation & github, please visit:
https://bezkoder.com/node-js-upload-excel-file-database/
Node.js Rest API that exports Excel File
If you send request to /api/excel/download
, the server will return a response with an Excel file tutorials.xlsx that contains data in MySQL table:
How to do this?
You need to set the HTTP header:
"Content-disposition" : "attachment; filename=[yourFileName]"
"Content-Type" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
You can find step by step for downloading Excel file in the tutorial:
Node.js Download Excel file example with exceljs
These are APIs to be exported:
Methods | Urls | Actions |
---|---|---|
POST | /api/excel/upload | upload an Excel File |
GET | /api/excel/tutorials | get List of items in db table |
GET | /api/excel/download | download db data as Excel file |
Further Reading
If you want to add Pagination while getting data from MySQL table, you can find the instruction at:
Server side Pagination in Node.js with Sequelize & MySQL
Or working with CSV file instead:
Node.js: Upload CSV file data into Database with Express
Fullstack:
- Vue.js + Node.js + Express + MySQL example
- Vue.js + Node.js + Express + MongoDB example
- Angular 8 + Node.js Express + MySQL example
- Angular 10 + Node.js Express + MySQL example
- Angular 11 + Node.js Express + MySQL example
- Angular 12 + Node.js Express + MySQL example
- React + Node.js + Express + MySQL example
Security: Node.js โ JWT Authentication & Authorization example
Deployment:
- Deploying/Hosting Node.js app on Heroku with MySQL database
- Dockerize Node.js Express and MySQL example โ Docker Compose
Node.js & MySQL Associations:
Top comments (0)