-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (48 loc) · 1.6 KB
/
index.js
File metadata and controls
58 lines (48 loc) · 1.6 KB
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
50
51
52
53
54
55
56
57
58
// Import necessary modules and configurations
const express = require("express");
const connection = require("./config/db"); // Assuming this module connects to your database
const { redisClient } = require("./config/redis"); // Assuming this module configures Redis
const rateLimiter=require("./config/rateLimit");
const expresswinston=require("express-winston");
const winston=require("winston");
const app = express();
app.use(rateLimiter);
app.use(expresswinston.logger({
transports:[
new winston.transports.File({
level:"info",
filename:"logs.log",
colorize:true
}),
new winston.transports.Console({
level:"warn",
colorize:true,
json:true
})
],
format:winston.format.prettyPrint()
}))
// Import route handlers
const authRoutes = require('./routes/authRoutes');
const taskRoutes = require('./routes/taskRoutes');
// Enable JSON parsing middleware for incoming requests
app.use(express.json());
// Define a simple route for the root endpoint
app.get("/", (req, res) => {
res.send("Task Master");
});
// Use the imported route handlers
app.use('/auth', authRoutes);
app.use('/tasks', taskRoutes);
// Set up the server to listen on a specific port
const PORT = process.env.PORT || 3100;
app.listen(PORT, async () => {
try {
// Connect to the database and log success
await connection;
console.log(`Server is running on port ${PORT}`);
} catch (error) {
// Log any errors that occur during startup
console.error("Error during server startup:", error);
}
});