-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (27 loc) · 918 Bytes
/
server.js
File metadata and controls
41 lines (27 loc) · 918 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
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express');
const app = express();
// todo routers -------
const todoRouter = require('./routes/todosRouter.js');
//importing error middleware --
const errorMiddlewares = require('./middleware/errorHandler.js');
// Add body parsing middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/api/todos', todoRouter);
//testing api -------
app.get('/', (req, res) => {
res.send('Welcome to Homepage !');
});
//attaching the error handling middleware ----------
//for logging error-->>
app.use(errorMiddlewares.errorLogger);
//for sending error in response -->>>
app.use(errorMiddlewares.errorResponder);
//for sending response to invalid paths --->>
app.use(errorMiddlewares.invalidPathHandler);
//port --------
const PORT = process.env.PORT || 8080;
//server -------
app.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);
});