-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (26 loc) · 949 Bytes
/
server.js
File metadata and controls
38 lines (26 loc) · 949 Bytes
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 app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static('public'));
const path = require('path');
const multer = require('multer');
const storage = multer.diskStorage({
destination: 'public/uploads/',
filename: function (req, file, callback) {
callback(null, file.originalname);
}
});
const uploading = multer({storage: storage});
app.get('/', (req, res) => res.sendFile(__dirname + '/' + 'index.html'));
app.post('/upload', uploading.single('image'), function (req, res) {
imagePath = '/uploads/' + req.file.originalname;
const response = {
message: 'Image has been uploaded',
path: imagePath
};
console.log(response);
res.json(JSON.stringify(response));
});
const server = app.listen(8081, () => console.log("Server is running!"));