-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 974 Bytes
/
index.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
//NOTE - import dotenv
import * as dotenv from 'dotenv';
//NOTE - configurations
dotenv.config();
//NOTE - import expressJS
import express from 'express';
const app = express();
const port = 3000;
//NOTE - CONNECT DATABASE
import { connection } from './database/connection.js';
connection();
import userRoutes from './src/modules/user/user.routes.js';
import taskRoutes from './src/modules/task/task.routes.js';
import { AppError } from './src/utils/AppError.js';
import { globalError } from './src/utils/GlobalErrorHandling.js';
app.use(express.json());
app.use("/user", userRoutes);
app.use("/task", taskRoutes);
app.use('*', (req, res, next) => {
// res.json({ Message: `Invalid Url ${req.originalUrl}` });
// next(new Error(`Invalid Url ${req.originalUrl}`));
next(new AppError(`Invalid Url ${req.originalUrl}`, 404));
})
//NOTE - Global Error Handling.
app.use(globalError);
app.listen(port, () => console.log(`Server is listening on port ${port}!`));