-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (40 loc) · 1.36 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import express from 'express';
import mongoose from 'mongoose';
import cookieParser from 'cookie-parser';
import userRouter from './Router/userRouter.js';
import projectRouter from './Router/projectRouter.js'
import taskRouter from './Router/taskRouter.js'
import taskBoardRouter from './Router/taskBoardRouter.js'
import dashboardRouter from './Router/dashboardRouter.js'
import logging from './middleware/logger.js';
import errorHandler from './middleware/errorHandler.js';
import notFoundHandler from './middleware/notFoundHandler.js';
import 'dotenv/config'
const app = express();
const port = process.env.PORT
// Middleware to parse JSON
app.use(express.json())
// Use cookieParser middleware
app.use(cookieParser())
// Logger Meddleware, Application-level middleware - Logging (whole application)
app.use(logging)
app.use('/user', userRouter);
app.use('/project', projectRouter)
app.use('/task', taskRouter)
app.use('/', taskBoardRouter)
app.use('/', dashboardRouter)
// notFound Handling Middleware
app.use(notFoundHandler)
// Error Handling Middleware
app.use(errorHandler);
// connect momgoDB campass Backend API
mongoose.connect(process.env.Connect)
.then(() => {
console.log("Database connection established");
})
.catch((err) => {
console.error("Database connection error:", err);
});
app.listen(port, () => {
console.log(`server is working on ${port}`);
});