-import type { Server } from 'http'
-import type { AddressInfo } from 'net'
+import type { Server } from 'node:http'
+import type { AddressInfo } from 'node:net'
import { ClusterWorker } from 'poolifier'
import express, { type Express, type Request, type Response } from 'express'
-import { type WorkerData, type WorkerResponse } from './types.js'
+import type { WorkerData, WorkerResponse } from './types.js'
-const factorial: (n: number) => number = (n) => {
+const factorial: (n: number) => number = n => {
if (n === 0) {
return 1
}
private static readonly startExpress = (
workerData?: WorkerData
): WorkerResponse => {
+ const { port } = workerData as WorkerData
+
const application: Express = express()
// Parse only JSON requests body
res.send({ number: factorial(parseInt(number)) }).end()
})
- ExpressWorker.server = application.listen(workerData?.port, () => {
+ ExpressWorker.server = application.listen(port, () => {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- `⚡️[express server]: Express server is started in cluster worker at http://localhost:${workerData?.port}/`
+ `⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/`
)
})
return {
status: true,
- port:
- (ExpressWorker.server.address() as AddressInfo)?.port ??
- workerData?.port
+ port: (ExpressWorker.server.address() as AddressInfo)?.port ?? port
}
}