-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (35 loc) · 1.11 KB
/
server.js
File metadata and controls
39 lines (35 loc) · 1.11 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
require("dotenv").config();
const ConnectDB = require("./config/DB")
const app = require("./app");
const mongoose = require("mongoose");
const winston = require("winston");
require("winston-daily-rotate-file");
const PORT = process.env.PORT || 5000;
// ===== Winston Logging Setup =====
const transport = new winston.transports.DailyRotateFile({
dirname: "logs",
filename: "server-%DATE%.log",
datePattern: "YYYY-MM-DD",
maxFiles: "14d",
});
const logger = winston.createLogger({
level: "info",
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [transport, new winston.transports.Console()],
});
// ===== Connect Database and Start Server =====
ConnectDB()
.then(() => {
app.listen(PORT, "0.0.0.0", () => {
logger.info(`✅ Server running on port ${PORT}`);
console.log(`✅ Server running on port ${PORT}`);
});
})
.catch((err) => {
logger.error("❌ MongoDB connection failed", err);
console.error("MongoDB connection failed:", err);
process.exit(1);
});