-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
27 lines (22 loc) · 743 Bytes
/
Copy pathindex.ts
File metadata and controls
27 lines (22 loc) · 743 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
import express from "express";
import Routers from './Routes/IndexRoute'
import multer from "multer";
const app = express();
app.use(express.json());
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads')
},
filename: function (req, file, cb) {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
cb(null, file.fieldname + '-' + uniqueSuffix)
}
})
const upload = multer({ storage: storage })
app.post('/profile', upload.single('image'), function (req, res, next) {
res.json('uploaded successfully')
})
app.use('/api', Routers)
app.listen(process.env.APP_PORT, () => {
console.log(`Server is running at http://localhost:${process.env.APP_PORT}`);
});