Created
October 22, 2021 23:28
-
-
Save Archakov06/40fee0bbf7c63e6b523a5147b8ab57f0 to your computer and use it in GitHub Desktop.
server.js
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 multer = require('multer'); | |
const cors = require('cors'); | |
const app = express(); | |
app.use(cors()); | |
app.use(express.static(__dirname)); | |
app.use( | |
multer({ | |
storage: multer.diskStorage({ | |
destination: function (req, file, cb) { | |
cb(null, './public'); | |
}, | |
filename: function (req, file, cb) { | |
cb(null, file.originalname); | |
}, | |
}), | |
}).single('file'), | |
); | |
app.post('/', function (req, res) { | |
let file = req.file; | |
if (!file) { | |
res.send('Ошибка при загрузке файла'); | |
} else { | |
res.send('Файл загружен'); | |
} | |
}); | |
app.listen(9999, () => { | |
console.log('Сервер запущен!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment