Created
September 28, 2020 03:10
-
-
Save dev-sankhadip/2eeb58ab43fd43241688702de18976d3 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
const express = require("express"); | |
const fileupload = require("express-fileupload"); | |
const cors = require("cors"); | |
const app = express(); | |
app.use(cors()); | |
app.use(fileupload()); | |
app.use(express.static("files")); | |
app.post("/upload", (req, res) => { | |
const newpath = __dirname + "/files/"; | |
const file = req.files.file; | |
const filename = file.name; | |
file.mv(`${newpath}${filename}`, (err) => { | |
if (err) { | |
res.status(500).send({ message: "File upload failed", code: 200 }); | |
} | |
res.status(200).send({ message: "File Uploaded", code: 200 }); | |
}); | |
}); | |
app.listen(3000, () => { | |
console.log("Server running successfully on 3000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment