-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (31 loc) · 907 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (31 loc) · 907 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
const express = require('express')
const path = require('path');
const app = express()
const port = 7000
const staticPath = path.join(__dirname, 'frontend');
const multer = require('multer');
const cors = require("cors");
app.use(express.static(staticPath));
const storage = multer.diskStorage({
destination: (req,file,cb)=>{
cb(null,'frontend/images')
},
filename: (req, file, cb) => {
// Preserve the original file extension
cb(null,file.originalname);
}
})
const upload = multer({storage: storage})
app.use(cors());
//app.use('/', express.static(__dirname + '/home'));
app.get('/home', (req, res) => {
res.sendFile(path.join(staticPath, 'index.html'));
});
app.post("/upload",upload.single("image"),(req,res)=>{
res.status(200).json({
message :"Image uploaded"
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})