tips for resolving pm2 issue in cluster mode when using ts-node

I'm having an issue using pm2 with ts-node for deployment.

Whenever I try to use cluster-mode, a pm2 instance error occurs, saying "Cannot find module..."

Error: Cannot find module '{path}/start'

at main ({path}/node_modules/ts-node/dist/bin.js:178:20)

at Object. ({path}/node_modules/ts-node/dist/bin.js:404:5)

Here is my ecosystem.config.js and

"production": "pm2-runtime start ecosystem.config.js --env production"
this is my package script.

module.exports = {
  apps: [
   {
            script: "ts-node",
            args: "./server.ts",
            instances: "max",
            exec_mode: 'cluster_mode',
            node_args: '-r esm'
            env_production: {...}
   }
  ]
}

However, when I switch to fork-mode instead of cluster-mode, the app functions correctly. I'm currently stuck on how to resolve this problem. If you have any ideas or solutions, please let me know.

Answer №1

It has come to my understanding that utilizing an interpreter other than JS necessitates fork mode, thereby hindering the direct execution of TypeScript. To enable cluster mode, one must compile /server.ts to /server.js.

https://pm2.keymetrics.io/docs/tutorials/using-transpilers-with-pm2#execution-interpreter

To seamlessly integrate transpilers with PM2, it is advisable to override the execution interpreter (exec_interpreter). However, changing this setting will restrict your code to only function in fork_mode.

Cluster and Fork mode distinction in PM2

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

Using a different schema in mongoose refers to the process of connecting and utilizing

Having some trouble building a basic website where users can post images and others can comment on them. I'm stuck trying to reference another schema. In the campground.js schema, comments are stored as an empty array within the campgrounds collectio ...

What is the best way to refresh the script located within the head tag of an index.html file in an Angular

I've been looking for solutions, but I can't seem to find one. In my index.html file, I've placed some script within the head tag (even above the </body> tag) and included a $(document).ready function. The issue I'm facing is th ...

Trouble displaying object in template using Angular's ngrx

Within my Typescript interface, I have declared the following structure: export interface FolderList { ADMIN: [Folder[], string, string]; SUPERADMIN: [Folder[], string, string]; USER: [Folder[], string, string]; } The 'Folder' interface is de ...

The Promise.all() function does not wait for the map function to finish resolving

Here is the code snippet that I am currently working with: const router = require("express").Router(); const Post = require("../models/Post"); const User = require("../models/User"); router.get("/timeline/all", asyn ...

Is there a way to merge the outcomes from these several SELECT queries into one consolidated result?

Here is the database schema and individual select statements provided. However, I am looking to retrieve all results from various queries at once. //SCHEMA.. The following is the database schema CREATE TABLE `orgs` ( `id` int(10) UNSIGNED NOT NULL AUTO ...

Error in Angular 2 after transition to @types: encountering "require" name not found issue

After transitioning my project from old typings to types-publisher, I have successfully resolved most of my dependencies. However, I am consistently encountering an error that reads Cannot find name 'require'. Below is a snippet from my tsconfig. ...

Oops! ExpressJs no longer includes some middleware like bodyParser

I am encountering the error message above every time I attempt to run my application. I cannot pinpoint which package I may have forgotten to add. The server was functioning perfectly before adding this document, so I am hopeful that the issue lies within ...

Retrieving a collection of data from MongoDB featuring today's date

How can I retrieve a list of items from MongoDB with today's date dynamically instead of hardcoding the date in my pushups.js file like "date":"2017-10-26T07:09:36.417Z? Take a look at the code snippet below: Here are the documents in my MongoDB: { ...

Having trouble initiating the server using npm start

Just starting out with nodeJs: I have created a server.js file and installed nodejs. However, when I try to run "npm start", I encounter the following errors. C:\Users\server\server.js:43 if (!(req.headers &amp;& req.headers. ...

Guide on successfully importing a pretrained model in Angular using TensorFlow.js

I need help with uploading a pretrained Keras model to my existing tensorflow.js model and then making simple predictions by passing tensors in the correct format. The model is stored locally within the project, in the assets folder. export class MotionAn ...

What are the specific purposes of utilizing semantic versioning (semver) notation within the package.json file?

Could someone clarify the specific distinctions between the semver notations found in package.json file? I'd appreciate a detailed explanation. ...

Is including takeUntil in every pipe really necessary?

I'm curious whether it's better to use takeUntil in each pipe or just once for the entire process? search = (text$: Observable<string>) => text$.pipe( debounceTime(200), distinctUntilChanged(), filter((term) => term.length >= ...

What is the reason behind having to refresh the page or switch to another tab for the field to display?

Currently, I am in the final stages of completing my update form. However, I am facing an issue with the conditional field. The select field should display a conditional field based on the selected value. The problem I'm encountering is that I need to ...

Create innovative applications by integrating ReactJS and Express.js, utilizing either a single or double port for seamless functionality

Is it possible to create an application with ReactJS and Express.js using both a single port and double port? What advantages come with developing an application using a single port compared to using two ports? I'm looking for some clarification on ...

Issue with Angular Provider Missing in Ahead-Of-Time Compilation

My goal is to simplify the declaration of a provider by using a static function in this way: const provider = MyModule.configureProvider(); @NgModule({ bootstrap: [AppComponent], declarations: [AppComponent], imports: [ ... ], providers: [ ...

How can I apply unique "compilerOptions" settings to a specific file in tsconfig.json file?

Can I apply specific tsconfig options to just one file? Here is my current tsconfig.json: { ... "compilerOptions": { ... "keyofStringsOnly": false, "resolveJsonModule": true, "esModuleInterop": t ...

Is Angular 9's default support for optional chaining in Internet Explorer possible without the need for polyfill (core-js) modifications with Typescript 3.8.3?

We are in the process of upgrading our system to angular 9.1.1, which now includes Typescript 3.8.3. The @angular-devkit/[email protected] utilizing [email protected]. We are interested in implementing the optional chaining feature in Typescript ...

Can you identify a specific portion within an array?

Apologies for the poorly titled post; summarizing my query into one sentence was challenging. I'm including the current code I have, as I believe it should be easy to understand. // Constants that define columns const columns = ["a", " ...

What is the best way to integrate ag-grid with Observable in Angular 2?

After conducting extensive research on the Internet, I am still struggling to connect the pieces. My angular2 application utilizes an Observable data source from HTTP and I am attempting to integrate ag-grid. However, all I see is a loading screen instead ...

Transferring information between pages within Next.js 13

I am currently working on a form that is meant to generate a Card using the information inputted into the form, which will then be displayed. While I have successfully implemented the printing feature, I am having difficulty transferring the form data to t ...