DEV Community

Cover image for Upload & Read Excel File in Node.js
Tien Nguyen
Tien Nguyen

Posted on • Updated on • Originally published at

Upload & Read Excel File in Node.js

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:

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:

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


Security: Node.js – JWT Authentication & Authorization example


Node.js & MySQL Associations:

Top comments (0)