-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (25 loc) · 990 Bytes
/
server.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
const express = require('express')
const path = require('path')
const app = express()
const multer = require('multer')
const {MergePdfs} = require('./testpdf.js')
const upload = multer({ dest: 'uploads/' })
const port = 3000
app.use('/static', express.static(path.join(__dirname, 'public')))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'templates/index.html')) // for using html file
})
app.post('/merge', upload.array('pdfs',2), async (req, res, next) => {
console.log(req.files)
let d = await MergePdfs(path.join(__dirname, req.files[0].path), path.join(__dirname, req.files[1].path))
res.redirect(`http://localhost:3000/static/${d}.pdf`)
setTimeout(() => {
fs.unlinkSync(path.join(__dirname, req.files[0].path))
fs.unlinkSync(path.join(__dirname, req.files[1].path))
}, 100000);
// res.send({data: req.files})
}
)
app.listen(port, () => {
console.log(`Example app listening on port http://localhost:${port}`)
})