Created
September 1, 2022 00:45
-
-
Save podolskyi/b7260f55ae9d1e7c1285bc5632a21c3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from "express"; | |
import cors from "cors"; | |
import multer from "multer"; | |
const app = express(); | |
//Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins | |
app.use(cors()); | |
const storage = multer.diskStorage({ | |
destination: (req, file, cb) => { | |
cb(null, __dirname + "/uploads"); | |
}, | |
filename: (req, file, cb) => { | |
cb(null, file.originalname); | |
}, | |
}); | |
const Data = multer({ storage: storage }); | |
app.post("/files", Data.any("files"), (req, res) => { | |
if (res.status(200)) { | |
console.log("Your file has been uploaded successfully."); | |
console.log(req.files); | |
res.json({ message: "Successfully uploaded files" }); | |
res.end(); | |
} | |
}); | |
app.listen(8000, () => { | |
console.log("Server is running"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment