Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

379
Views
How to implement cluster module of node js on serverless-http

I'm implementing cluster module of nodeJS on serverless. cluster couldn't listen serverless port so after running serverless I'm getting following issue

offline: Failure: offline: handler 'handler' in /home/Documents/cluster is not a function
Error: offline: handler 'handler' in /home/Documents/cluster is not a function
    at InProcessRunner.run (/home/Documents/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:160:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async LambdaFunction.runHandler (/home/Documents/node_modules/serverless-offline/dist/lambda/LambdaFunction.js:368:20)
    at async hapiHandler (/home/Documents/node_modules/serverless-offline/dist/events/http/HttpServer.js:702:18)
    at async exports.Manager.execute (/home/Documents/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
    at async Object.internals.handler (/home/Documents/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at async exports.execute (/home/Documents/node_modules/@hapi/hapi/lib/handler.js:31:20)
    at async Request._lifecycle (/home/Documents/node_modules/@hapi/hapi/lib/request.js:371:32)
    at async Request._execute (/home/Documents/node_modules/@hapi/hapi/lib/request.js:281:9)

following is my cluster

cluster.js

const cluster = require("cluster");
const totalCPUs = require("os").cpus().length;
const serverless = require("serverless-http");
const app = require("./api");

console.log("cluster.isMaster", cluster.isMaster);
if (cluster.isMaster) {
  console.log(`Number of CPUs is ${totalCPUs}`);
  console.log(`Master ${process.pid} is running`);

  // Fork workers.
  for (let i = 0; i < totalCPUs; i++) {
    cluster.fork();
  }

  cluster.on("exit", (worker, code, signal) => {
    // console.log(`process killed:`, worker.kill());
    console.log(`${worker.process.pid} is killed`);
    // console.log("code, signal ", code, signal);
    cluster.fork();
    // console.log(`new proccess pid: ${process.pid}`);
  });
} else {
  module.exports.handler = serverless(app);
}

app.js

const express = require("express");
const app = express();
// require("dotenv").config()
const cluster = require("cluster");
const totalCPUs = require("os").cpus().length;
app.get("/", (req, res) => {
  console.log(`Hello World! - on process ${process.pid}`);
  res.send("Hello World!");
  // process.exit(0);
});
module.export = app

after all this it automatically kill the all the process.

 -  15947 is killed
 -  15961 is killed
 -  15968 is killed
 -  15954 is killed

How I can integrate cluster in serverless.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!