forked from TEAM-C10-KM-BINAR-BATCH-5/backend-mooc-binar-c10
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (22 loc) · 627 Bytes
/
server.js
File metadata and controls
28 lines (22 loc) · 627 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
26
27
28
// Import required modules
require('dotenv').config()
const express = require('express')
const cors = require('cors')
// Create an Express app
const app = express()
// Import custom modules
const ApiError = require('./utils/apiError')
const errorHandler = require('./controllers/errorController')
const router = require('./routes')
// Use other middlewares
app.use(express.json())
app.use(cors())
app.use(router)
// Handle 404 errors
app.all('*', (req, res, next) => {
next(new ApiError('Routes does not exist', 404))
})
// Error handling middleware
app.use(errorHandler)
// Export the Express app
module.exports = app