-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREST_API.js
More file actions
40 lines (25 loc) · 738 Bytes
/
Copy pathREST_API.js
File metadata and controls
40 lines (25 loc) · 738 Bytes
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
const express = require('express');
const mongoose = require('mongoose');
const userRouter = require('./router/user');
const studentRouter = require('./router/student');
const cluster = require("node:cluster");
const os = require("os");
const cpuCount = os.cpus().length;
if(cluster.isPrimary)
{
for(let i=0;i<cpuCount;i++)
{
cluster.fork();
}
}
else
{
const app = express();
const port = 7777;
mongoose.connect('mongodb://127.0.0.1:27017/userDatabase')
.then(()=>{console.log("Database connected...........................")});
app.use(express.urlencoded({extended:false}));
app.use('/users',userRouter);
app.use('/student',studentRouter);
app.listen(port,()=>{console.log(`server is runing on port ${port}`)});
}