pm2-discord-ts
This is a PM2 Module for sending events from your PM2 process to Discord Webhook.
ā ļø This new version of the module is no longer the same as original style of (pm2-discord). You may still use the old one by installing the version 1.1.2.
Install
$ pm2 install pm2-discord-ts
Setup
pm2 set pm2-discord-ts:url <Webhook URL>
Events
Events are now in array.
The following events can be subscribed to:
- log - All standard out logs. Default:
true
- error - All error logs. Default:
true
- kill - Event fired when PM2 is killed. Default:
false
- exception - Any exceptions from your processes. Default:
false
- restart - Event fired when a process is restarted. Default:
true
- delete - Event fired when a process is removed from PM2. Default:
false
- stop - Event fired when a process is stopped. Default:
true
- restart overlimit - Event fired when a process is reaches the max amount of times it can restart. Default:
true
- exit - Event fired when a process is exited. Default:
false
- start - Event fired when a process is started. Default:
false
- online - Event fired when a process is online. Default:
false
# pm2 set pm2-discord-ts:events log | log,error
$ pm2 set pm2-discord-ts:events <events,events>
Options
- url - Webhook URL. Required.
- embeds - Send embeds instead of text. Default:
false
- includeProcessName - Include the process name in the message. Default:
true
- suppressError - Suppress the error if occured. Default:
false
- processTarget (string[] | null) - The process name/id to only emit for. Default:
null
- buffer (bool) - Enable/Disable buffering of messages by timestamp. Messages that occur with the same timestamp (seconds) will be concatenated together and posted as a single message. Default:
true
- bufferDuration (number) - Duration in seconds to aggregate messages. Has no effect if buffer is set to false. Min:
1
, Max: 5
, Default: 1
- maxQueue (number) - Number of messages to keep before the queue will be truncated. When the queue exceeds the value, a rate limit message will be sent. Min:
10
, Max: 100
, Default: 100
Always restart the module after changing any of the options.
# pm2 set pm2-discord-ts:buffer true
$ pm2 set pm2-discord-ts:<key> <value>
$ pm2 restart pm2-discord-ts
Embeds Preview:


API
import Log, { Events } from 'pm2-discord-ts';
import ANSI from 'strip-ansi';
const process = new Log({
events: [Events.Log, Events.Error],
suppressError: true,
processTarget: [ 'my-project' ]
});
process.start();
process.on("*", (data, event: Events) => {
console.log(`Process ${data.process.name} emitted event ${event}`);
});
process.on("log", (data) => {
Channel.send({
content: ANSI(data.data)
});
})
Methods
- start(pause?: boolean) - Start listening to the bus.
- pause(toggle?: boolean) - Pause listening to the bus.
Todo
Done