Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable pm2 log creation in node js

I am using aws ubuntu instance for my application and using node js to sync data from third party apis.

I have 6 node js scripts that calls every minute to sync data by making http request for many users.

For process management I am using PM2 module of node js.This pm2 creates logs for each running file ,this files size increasing tremendously and instance space occupied by log files.

Is there any way to disable pm2 log creation?

like image 332
Ankit Badiya Avatar asked Jun 10 '16 09:06

Ankit Badiya


People also ask

How do you stop a pm2 process?

How to disable monitoring for a specific process? You can then use the command `pm2 unmonitor [APP_NAME|ID]` to stop monitoring a process with PM2 Plus. `pm2 ls` will display a red dot indicating the application will not be monitored by PM2 Plus. If you want to monitor the process again use `pm2 monitor [APP_NAME|ID]`.

Does pm2 need to be installed globally?

yes, you need to install it globally.

What does pm2 do in node JS?

PM2 is a production process manager for Node. js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.


1 Answers

We can user pm2 application declaration for our purpose and we can use:

Disabling logs
You can pass /dev/null to error_file or out_file to disable logs saving.

We can also set max_memory_restart parameter in process.json apps to set autorestart process on certain memory occupied by memory.example below for process.json:

{
  "apps" : [{
      "script": "worker.js",
      "watch": true,
      "max_memory_restart": "50M",
      "error_file": "/dev/null"
  }]
}
like image 161
Ankit Badiya Avatar answered Sep 19 '22 13:09

Ankit Badiya