abderrezague mohamed :
I am using multer for uploading the file and xlsx to process it and mongodb as a database (mongoose for the model):\nLead is the data model, you have to add the Excel sheet columns name. See mongoose documentation for more information\nconst express = require("express");\nconst multer = require("multer");\nconst connectDB = require("./config/db");\nconst Lead = require("./models/Lead");\n\nconnectDB();\n\nconst uploadXLSX = async (req, res, next) => {\n try {\n let path = req.file.path;\n var workbook = XLSX.readFile(path);\n var sheet_name_list = workbook.SheetNames;\n let jsonData = XLSX.utils.sheet_to_json(\n workbook.Sheets[sheet_name_list[0]]\n );\n if (jsonData.length === 0) {\n return res.status(400).json({\n success: false,\n message: "xml sheet has no data",\n });\n }\n let savedData = await Lead.create(jsonData);\n\n return res.status(201).json({\n success: true,\n message: savedData.length + " rows added to the database",\n });\n } catch (err) {\n return res.status(500).json({ success: false, message: err.message });\n }\n};\n\nvar storage = multer.diskStorage({\n destination: function (req, file, cb) {\n cb(null, "uploads");\n },\n filename: function (req, file, cb) {\n cb(null, Date.now() + "-" + file.originalname);\n },\n});\n\nconst upload = multer({ storage: storage });\n\napp.post("/upload", upload.single("xlsx"), uploadXLSX);\n\nconst port = process.env.PORT || 5000;\n\nconst server = app.listen(port, () => {\n console.log("app running on port", port);\n});\n\nSo from here when you make a call to localhost:5000/upload with postman see picture below\n",
2022-06-02T15:33:19