-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (27 loc) · 1.02 KB
/
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 required modules
const express = require('express');
const dotenv = require('dotenv').config();
const cors = require('cors');
// Set the port number to use, default to 5000
const port = process.env.PORT || 5000;
// Import custom error handler middleware
const { errorHandler } = require('./middlewares/errorMiddleware');
// Connect to the database
const connectDB = require('./config/db');
connectDB();
// Create an instance of the express app
const app = express();
// enable CORS for all routes
app.use(cors());
// Set up middleware for parsing JSON and URL encoded data
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Set up routes for handling user requests
app.use('/', require('./routes/userRoutes'));
app.use('*', (req, res) => {
res.send('not available');
});
// Use the custom error handler middleware to handle errors
app.use(errorHandler);
// Start the server and listen for requests on the specified port
app.listen(port, () => console.log(`server running on port ${port}`));