-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 875 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
const express = require('express');
const cors = require('cors');
const multer = require('multer');
require('dotenv').config()
const app = express();
// Middleware
app.use(cors());
app.use('/public', express.static(process.cwd() + '/public'));
app.use((req,res,next)=>{
console.log(`${req.method} ${req.url}`)
return next()
})
// Serve Homepage
app.get('/', function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
// Handle files
const upload = multer({dest:'./public/uploads/'})
app.post('/api/fileanalyse',upload.single('upfile'),(req,res)=>{
const name = req.file.originalname
const type = req.file.mimetype
const size = req.file.size
const response = {name,type,size}
res.json(response)
})
// Start Server
const port = process.env.PORT || 3000;
app.listen(port, function () {
console.log('Your app is listening on port ' + port)
});