This repository has been archived on 2023-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
freecodecamp-projects/6-backend-dev/5-file-metadata/index.js

29 lines
702 B
JavaScript

const express = require('express');
const cors = require('cors');
const multer = require('multer')
const upload = multer({ dest: 'uploads/' })
require('dotenv').config()
const app = express();
app.use(cors());
app.use('/public', express.static(process.cwd() + '/public'));
app.get('/', function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
app.post('/api/fileanalyse', upload.single('upfile'), (req, res) => {
console.log(req.file)
res.json({
name: req.file.originalname,
type: req.file.mimetype,
size: req.file.size
})
})
const port = process.env.PORT || 3000;
app.listen(port, function () {
console.log('Your app is listening on port ' + port)
});