There are several modules available in Node.js that you can use to generate Excel files. Here are a few examples:
1. exceljs
First, install:
```
npm install exceljs
```
Then generate Excel:
```
let Excel = require(‘exceljs’);
let workbook = new Excel.Workbook();
let worksheet = workbook.addWorksheet(‘My Sheet’);
worksheet.columns = [
{header: ‘Id’, key: ‘id’},
{header: ‘Name’, key: ‘name’},
{header: ‘D.O.B.’, key: ‘dob’}
];
worksheet.addRow({id: 1, name: ‘John Doe’, dob: new Date(1970,1,1)});
workbook.xlsx.writeFile(‘MyExcelFile.xlsx’)
.then(function() {
console.log(‘File is written’);
});
```
1. xlsx
First, install:
```
npm install xlsx
```
Then generate Excel:
```
let XLSX = require(‘xlsx’);
let workbook = XLSX.utils.book_new();
let worksheet = XLSX.utils.json_to_sheet([
{id: 1, name: ‘John Doe’, dob: ’01-01-1970’},
{id: 2, name: ‘Jane Doe’, dob: ’01-01-1970’}
]);
XLSX.utils.book_append_sheet(workbook, worksheet, ‘My Sheet’);
XLSX.writeFile(workbook, ‘MyExcelFile.xlsx’);
```
These are simple examples of creating an Excel file with a single worksheet and a few rows. Of course, these modules provide more complex functionality (such as formatting cells, adding multiple sheets, etc.) so you can check their respective documentation for more details.