pm2 is launching multiple instances of identical next.js applications

I am in the process of deploying my Next.js app on my local PC.

Below are the contents of my configuration and package.json files:

// package.json
{
  "name": "smarf",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "axios": "^0.25.0",
    "modbus-serial": "^8.0.5",
    "mongoose": "^6.1.7",
    "next": "12.0.8",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "swr": "^1.1.2"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.2",
    "eslint": "8.7.0",
    "eslint-config-next": "12.0.8",
    "postcss": "^8.4.5",
    "tailwindcss": "^3.0.15"
  }
}
// ecosystem.config.json
{
  "apps": [
    {
      "name": "smarf",
      "cwd": "./",
      "script": "node_modules/next/dist/bin/next",
      "args": "start",
      "instances": -1,
      "exec_mode": "cluster",
      "autorestart": false,
      "max_memory_restart": "2G",

      "output": "~/logs/pm2/console.log",
      "error": "~/logs/p*my/onsoleError.log"
    }
  ]
}

Upon running the command:

pm2 start ecosystem.config.json

It seems that multiple command windows (exactly 11 windows) open and close, resulting in 11 instances of the same application running on my computer. 11 processes

Deleting processes 1-10 does not seem to affect the application's performance.

Could this be a configuration error or possibly a bug?

Answer №1

Special thanks to @Yash Kumar Verma for providing valuable feedback,

The term "instances" refers to the quantity of hardware resources utilized during the application's operation.

After adjusting instances from -1 to 1, the functionality has significantly improved.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it more advantageous to create two distinct projects for the frontend and backend along with an API, or should I consolidate them into a

Asking for some guidance on a few queries I have. I've developed a backend node server with express & mongo to run specific tasks and store them in the database, along with creating an admin page using express & bootstrap. Everything is functioning s ...

What is the best way to create operating system-neutral file paths in Node.js?

I'm currently fixing issues with my code while running integration tests on an EC2 instance of a Windows machine. Despite resolving the filenames-are-too-long problem, several paths remain unresolved due to being hardcoded for UNIX systems. I've ...

Unable to send multiple cookies using custom headers in Next.js configuration

I am using custom headers to set the cookie in my next.config.js file. The refresh token is successfully set, but for some reason the second token is not being recognized. key: 'Set-Cookie', value: `RefreshTokenKey = " ...

Managing embedded URLs in Next.js applications

I am currently in the process of developing an ecommerce platform, expecting users to utilize both our domain and their own custom domains. For example: ourplatform.com/username theirdomain.com My goal is to customize the inline links based on the speci ...

There was an issue with the Discord.js (v12) Giveaway Command that resulted in an error stating "Error: Cannot read property 'hasPermission' of undefined"

Hey everyone, I'm trying to develop my own Discord bot and I want to add a giveaway command to it. I found an example code online that I tried to implement, but unfortunately, it's not working as expected... const ms = require('ms'); c ...

JavaScript - Sort an array containing mixed data types into separate arrays based on data

If I have an array such as a=[1,3,4,{roll:3},7,8,{roll:2},9], how can I split it into two arrays with the following elements: b=[1,3,4,7,8,9] c=[{roll:3},{roll:2}]. What is the best way to separate the contents of the array? ...

Tips for creating a module in ECMAScript 6

You can find the following code functioning with nodejs 4.4: "use strict"; const test = (res) => { return (data) => { return res.json({"message": "testing"}); }; }; module.exports = test; I'm wondering if using const is prope ...

Installing a package from a private repository using a different package name with npm

I'm looking to incorporate a module from a private GitHub repository into my project. To achieve this, I will execute the command npm install git+https://[API-KEY]:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b737c6e607 ...

What is the process for integrating a new ACL middleware into my system?

I am currently implementing a client access control system based on IP ACL. function localAcl (options) { let {allowedMethods} = options if (!Array.isArray(allowedMethods)) { allowedMethods = [] } return function(req, res, next) { ...

express not resolving async callback

Exploring the concept of promises further, I decided to create a simple async delay function that incorporates a timeout feature: const app = express(); function timeout(duration) { return new Promise((resolve, reject) => setTimeout(() => { ...

Converting city/country combinations to timezones using Node.js: A comprehensive guide

When provided with the name of a city and country, what is the most reliable method for determining its timezone? ...

Troubleshooting the missing next-auth/client module error in a Next.js project

Currently, I am tackling a project in nextjs that involves Prisma and GitHub authentication. However, when I run npm run dev, the project fails to compile. The error is visible in this image: https://i.stack.imgur.com/HC8dc.png How can I troubleshoot and ...

Next.js reports an error of type TypeError when attempting to read properties of undefined, specifically 'headers'

I've been working on utilizing OpenAI's API to develop an app using Next.js for generating multiple-choice and open-ended questions. However, when testing the endpoint in Postman, I encountered the following error: error TypeError: Cannot read ...

How come running `npm install <folder>` results in installing different dependencies compared to `npm install lib`?

My current project, project1, relies on <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5221262b3e37367f313d3f223d3c373c262112667c6">[email protected]</a>. When attempting to integrate project2 into project1 as a ...

Unauthorized access: The defaultCookies variable is not defined in Next-Auth

Has anyone else come across this error message while using next/auth version 3.27.3 in their app? error - unhandledRejection: ReferenceError: defaultCookies is not defined at C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-pr ...

The Embla Carousel feature is not compatible with next.js server-side rendering (SSR

My component is rendered server side (next.js). Embla Carousel does not work with server rendering. const [viewportRef, embla] = useEmblaCarousel( { slidesToScroll: "auto", axis: "y", skipSnaps: true, ...

User update function is not being triggered by Ionic 2 Express call

I am currently working on implementing a feature in my Ionic 2 program that updates a user field when triggered. The code snippet below is from my user-service.ts file: // Update a user update(user: User): Observable<User> { let url = `${this.u ...

What is the best way to store changing images in a Next.js application?

Is it possible to set the cache-control for images in a list of objects received from an API? Each object in the list contains a property called imageUrl, which is the link to the image. ...

Upload a user-sent image to a remote SFTP server for safekeeping

Can someone help me figure out how to upload a file to an SFTP remote server using ssh2-sftp-client? I am trying to retrieve the file from the user via a post request along with the destination. To process the file, I am utilizing multer. const Client = r ...

Nextjs version 13 encountered hydration failure due to discrepancies between the initial UI and the server-rendered content

I am currently utilizing the latest version 13.1.0. I have implemented a ContextProvider that allows switching between light and dark themes. 'use client'; import { Theme, ThemeContext } from '@store/theme'; import { ReactNode, useState ...