-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (25 loc) · 754 Bytes
/
server.js
File metadata and controls
25 lines (25 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const app = express();
const port = 3000;
app.use(cors());
app.use(express.json());
// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/BlackCoffer', { }).then(() => {
console.log('Connected to MongoDB');
}).catch((error) => {
console.error('Failed to connect to MongoDB:', error);
});
// Define API routes
const dataRoutes = require('./routes/dataRoutes');
app.use('/api', dataRoutes);
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Internal Server Error');
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});