-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.js
39 lines (34 loc) · 1.07 KB
/
Server.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
// Import Keys
const keys = require("./config/keys")
const express = require("express");
const app = express()
const cors = require('cors');
app.use(cors());
require('dotenv').config();
app.use(express.json());
// Bring the service file here and apply the changes
require('./Services/cache');
const authrouter = require('./Router/AuthRouter');
const router = require('./Router/NoteRouter')
const AuthMiddleware = require('./MiddleWare/Authorize')
// Cluster Module
const cluster = require('cluster')
cluster.schedulingPolicy = cluster.SCHED_RR;
app.use('/auth', authrouter);
app.use('/api', AuthMiddleware, router);
if (cluster.isMaster) {
cluster.fork();
} else {
console.log("Now, I'm Child Process");
const PORT = keys.PORT;
const { ConnectDB } = require("./ConnecttoMongoDB/Connection")
const StartServer = async () => {
try {
await ConnectDB(keys.MONGOURL)
app.listen(PORT, console.log(`Server is Listening on PORT...... ${PORT}`))
} catch (err) {
console.log(err.message);
}
}
StartServer();
}