New project structure

New folder structure
Changed to type:module
Moved routes to separate files
This commit is contained in:
2020-07-17 22:07:55 +02:00
parent ad8ed283d2
commit 2abec5017f
28 changed files with 1252 additions and 305 deletions

35
routes/routeImg.js Normal file
View File

@@ -0,0 +1,35 @@
import express from "express";
import multer from "multer";
var router = express.Router();
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "./images");
},
filename: function (req, file, cb) {
cb(
null,
new Date() //Date.now().toString
.toISOString()
.trim()
.replace(/[:_ -.]/g, "") +
Math.floor(Math.random() * 5000 + 1) +
file.mimetype.replace("/", ".")
);
},
});
const upload = multer({
storage: storage,
fileFilter: function (req, file, cb) {
if (file.mimetype !== "image/jpg") {
return cb(null, false);
}
cb(null, true);
},
limits: { fileSize: 4000000 },
}); //max file size = 4Mb
router.post("/", upload.single("menuiImage"), (req, res) => {
res.sendStatus(201);
});
export default router;