forked from restuwahyu13/express-mvc-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (29 loc) · 847 Bytes
/
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
require('module-alias/register')
const cluster = require('cluster')
const os = require('os')
const http = require('http')
const { app } = require('./app')
const { Route } = require('./core/Route')
class App extends Route {
init() {
if (cluster.isMaster) {
let cpuCore = os.cpus().length
for (let i = 0; i < cpuCore; i++) {
cluster.fork()
}
cluster.on('online', (worker) => {
if (worker.isConnected()) console.log(`worker is active ${worker.process.pid}`)
})
cluster.on('exit', (worker) => {
if (worker.isDead()) console.log(`worker is dead ${worker.process.pid}`)
cluster.fork()
})
} else {
//init default route
app.use(super.init())
// listenint server port
http.createServer(app).listen(process.env.PORT)
}
}
}
new App().init()