const express = require('express'); const multer = require('multer'); const path = require('path'); const fs = require('fs'); const app = express(); const indexRouter = require('./routes/index'); // Set up view engine app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'pug'); // Set up static files app.use(express.static(path.join(__dirname, 'public'))); app.use('/data', express.static(path.join(__dirname, 'data'))); // Add this line // Set up multer for file uploads const storage = multer.diskStorage({ destination: (req, file, cb) => { cb(null, 'data/'); }, filename: (req, file, cb) => { cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname)); } }); const upload = multer({ storage: storage }); // Routes app.use('/', indexRouter); app.post('/upload', upload.single('image'), (req, res) => { res.redirect('/'); }); // Start server const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`Server running on port ${port}`); }); module.exports = app;