-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (31 loc) · 1020 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require('express');
const path = require('path');
const dataModel = require('./models/user.model');
const XLSX = require('xlsx');
const port = process.env.PORT || 8000;
require("./db/conn");
const app = express();
app.use(express.json());
app.use(express.static(path.resolve(__dirname,'outputFiles')));
app.get('/web',(req,res)=>{
var wb = XLSX.utils.book_new(); //new workbook
dataModel.find((err,data)=>{
if(err){
console.log(err)
}else{
var temp = JSON.stringify(data);
temp = JSON.parse(temp);
var ws = XLSX.utils.json_to_sheet(temp);
var down = __dirname+'/outputFiles/databse.xlsx'
XLSX.utils.book_append_sheet(wb,ws,"sheet1");
XLSX.writeFile(wb,down);
res.download(down);
res.status(200).json({
msg:"excel downloaded"
})
}
});
});
app.listen(port,()=>{
console.log(`server running at ${port}`);
})