-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.1 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
const express = require('express');
const multer = require('multer');
const cors = require('cors');
const fs = require('fs');
const upload = multer({ dest: 'uploads/' })
require('dotenv').config()
const app = express();
app.use(cors());
app.use('/public', express.static(process.cwd() + '/public'));
app.get('/', function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
app.post('/api/fileanalyse', upload.single('upfile'), (req, res) => {
try {
const file = req.file;
const fileInfo = {
name: file.originalname,
type: file.mimetype,
size: file.size
}
fs.unlink(file.path, (err) => {
if (err) {
console.error(err);
return;
}
console.log('File deleted successfully');
});
res.json(fileInfo);
} catch (err) {
console.error(err.stack);
if(process?.env?.ENVIRONMENT === 'DEV') {
res.status(500).send(err.stack);
}
else {
res.status(500).send("Server Error");
}
}
});
const port = process.env.PORT || 3000;
app.listen(port, function () {
console.log('Your app is listening on port ' + port)
});