-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
35 lines (28 loc) · 892 Bytes
/
server.js
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
26
27
28
29
30
31
32
33
34
35
import dotenv from 'dotenv';
import express from 'express';
import cors from 'cors';
import connectDB from './src/config/database.js'; // Add the .js extension if it's a local file
import router from './src/routes/api.js'; // Add the .js extension if it's a local file
dotenv.config();
const app = express();
// Middleware
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// API Routes
app.use('/api', router);
// Connect to MongoDB
connectDB();
// Basic route for testing
app.get('/', (req, res) => {
res.json({ message: 'Welcome to VocalTrainingDB API' });
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: 'Something went wrong!' });
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});