Vibed it... :(
This commit is contained in:
37
backend/server.js
Normal file
37
backend/server.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const mongoose = require('mongoose');
|
||||
require('dotenv').config();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 5000;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// MongoDB connection
|
||||
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/recipe-management';
|
||||
mongoose.connect(MONGODB_URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
|
||||
const db = mongoose.connection;
|
||||
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
|
||||
db.once('open', () => {
|
||||
console.log('Connected to MongoDB');
|
||||
});
|
||||
|
||||
// Routes
|
||||
app.use('/api/recipes', require('./routes/recipes'));
|
||||
app.use('/api/users', require('./routes/users'));
|
||||
app.use('/api/selections', require('./routes/selections'));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Recipe Management API is running!' });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user