This project is a Node.js backend application utilizing Express and ExcelJS to generate downloadable Excel files from JSON data. It provides a RESTful API endpoint that accepts JSON input, processes it, and outputs a generated Excel file for download.
Perfect for backend developers working with file generation, this project highlights best practices in Node.js for creating Excel files dynamically with JavaScript.
- Excel File Generation: Transforms JSON data into an Excel file using ExcelJS, ready for download.
- Express API Endpoint: A POST route for JSON payload processing and Excel file output.
- Node.js Data Streaming: Efficiently streams the generated Excel file for direct download, improving performance.
- Modular Architecture: Organized with Express best practices, including controllers, services, routes, and TypeScript interfaces.
Here’s an overview of the project layout:
└── excel-generator-app/
├── package-lock.json
├── package.json
├── screenshots/
│ ├── S_node.js.png
│ └── S_postman.png
├── src/
│ ├── controllers/
│ │ └── excelController.ts
│ ├── index.ts
│ ├── interfaces/
│ │ └── productInterface.ts
│ ├── routes/
│ │ └── excelRoute.ts
│ └── services/
│ └── excelGenerationService.ts
├── tsconfig.json
-
Clone the repository:
git clone https://github.com/dev-luckymhz/node.js-express-excel-generator.git cd excel-generator-app
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
The server will run on http://localhost:3000
.
-
Open Postman or any API testing tool.
-
Send a
POST
request tohttp://localhost:3000/api/generate-excel
. -
In the request body, select JSON format and include product data in JSON. Here's a sample JSON payload:
[ { "id": 1, "name": "Product 1", "price": 100, "quantity": 20 }, { "id": 2, "name": "Product 2", "price": 200, "quantity": 30 }, { "id": 3, "name": "Product 3", "price": 300, "quantity": 15 }, { "id": 4, "name": "Product 4", "price": 400, "quantity": 25 }, { "id": 5, "name": "Product 5", "price": 500, "quantity": 10 } ]
-
In Postman, select "Send and Download" to receive the generated Excel file as a download.
- Node.js - JavaScript runtime environment for building backend applications.
- Express - Lightweight, flexible framework for creating APIs in Node.js.
- ExcelJS - Excel manipulation library used for backend file generation and handling in JavaScript.
This project is licensed under the MIT License. See the LICENSE file for details.