-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.js
31 lines (25 loc) · 828 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
31
// Your Node.js code here
const express = require('express')
const fileUpload = require('express-fileupload')
const app = express()
const port = 3000
//middleware
app.use(express.json())
app.use(fileUpload({
//limits: { fileSize: 50 * 1024 * 1024 },
createParentPath: true,
}));
//endpoints
app.use('/', express.static('dist'))
app.post('/upload', (req, res) => {
const file = req.files.file;
console.log(`File: ${file}`);
console.log(`Description: ${req.body.description}`);
//only handling file based on scope, abandoning description
file.mv(`./dist/uploaded_files/${file.name}`, function(err) {
if (err)
return res.status(500).send(err);
res.status(200).send('File uploaded!');
});
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))