-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver2.js
37 lines (33 loc) · 965 Bytes
/
server2.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 app = express();
const router = express.Router();
const path = require("path");
const multer = require("multer");
//để có thể nhận được dữ liệu tu req.body.
app.use(express.json());
const storage = multer.diskStorage({
destination: "./public/uploads/",
filename: function (req, file, cb) {
cb(null, "IMAGE-" + Date.now() + path.extname(file.originalname));
},
});
const upload = multer({
storage: storage,
limits: { fileSize: 1000000 },
}).single("myImage");
app.post("/upload",function (req, res, next) {
console.log("Request body ---1", req.body);
console.log("Request file ---", req.file); //Here you get file.
return res.status(200).json({
message: 'thanh cong'
})
});
app.get('/',(req,res,next)=> {
res.status(200).json({
hoa:'hoa'
});
})
const port = process.env.PORT || 5000;
app.listen(port, function () {
console.log("App listening on port " + port);
});