PageSourceSearch

https://discordjs-guide.netlify.app/assets/pm2.html.efa5852c.js

js discordjs-guide.netlify.app collected 2026-10-03 10:39:42 UTC 8,714 bytes, 16 lines download raw bytes

1import{r as o,o as c,c as l,b as s,w as n,a,F as u,d as e,f as r}from"./app.1a0d0096.js";const d={},h=a("h1",{id:"managing-your-bot-process-with-pm2",tabindex:"-1"},[a("a",{class:"header-anchor",href:"#managing-your-bot-process-with-pm2","aria-hidden":"true"},"#"),e(" Managing your bot process with PM2")],-1),m=a("p",null,`PM2 is a process manager. It manages your applications' states, so you can start, stop, restart, and delete processes. It offers features such as monitoring running processes and setting up a "start with operating system" (be that Windows, Linux, or Mac) so your processes start when you boot your system.`,-1),g=a("h2",{id:"installation",tabindex:"-1"},[a("a",{class:"header-anchor",href:"#installation","aria-hidden":"true"},"#"),e(" Installation")],-1),b=a("p",null,"You can install PM2 via the following command:",-1),f=a("div",{class:"language-bash ext-sh"},[a("pre",{class:"language-bash"},[a("code",null,[a("span",{class:"token function"},"npm"),e(),a("span",{class:"token function"},"install"),e(),a("span",{class:"token parameter variable"},"--global"),e(` pm2
2`)])])],-1),_=a("div",{class:"language-bash ext-sh"},[a("pre",{class:"language-bash"},[a("code",null,[a("span",{class:"token function"},"yarn"),e(" global "),a("span",{class:"token function"},"add"),e(` pm2
3`)])])],-1),y=a("div",{class:"language-bash ext-sh"},[a("pre",{class:"language-bash"},[a("code",null,[a("span",{class:"token function"},"pnpm"),e(),a("span",{class:"token function"},"add"),e(),a("span",{class:"token parameter variable"},"--global"),e(` pm2
4`)])])],-1),v=a("div",{class:"language-bash ext-sh"},[a("pre",{class:"language-bash"},[a("code",null,[e("bun "),a("span",{class:"token function"},"add"),e(),a("span",{class:"token parameter variable"},"--global"),e(` pm2
5`)])])],-1),k=r(`<h2 id="starting-your-app" tabindex="-1"><a class="header-anchor" href="#starting-your-app" aria-hidden="true">#</a> Starting your app</h2><p>After you install PM2, the easiest way you can start your app is by going to the directory your bot is in and then run the following:</p><div class="language-bash ext-sh"><pre class="language-bash"><code>pm2 start your-app-name.js
6</code></pre></div><h3 id="additional-notes" tabindex="-1"><a class="header-anchor" href="#additional-notes" aria-hidden="true">#</a> Additional notes</h3><p>The <code>pm2 start</code> script allows for more optional command-line arguments.</p><ul><li><code>--name</code>: This allows you to set the name of your process when listing it up with <code>pm2 list</code> or <code>pm2 monit</code>:</li></ul><div class="language-bash ext-sh"><pre class="language-bash"><code>pm2 start your-app-name.js <span class="token parameter variable">--name</span> <span class="token string">&quot;Some cool name&quot;</span>
7</code></pre></div><ul><li><code>--watch</code>: This option will automatically restart your process as soon as a file change is detected, which can be useful for development environments:</li></ul><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>pm2 start your-app-name.js <span class="token parameter variable">--watch</span>
8</code></pre><div class="line-numbers"><span class="line-number">1</span><br></div></div>`,9),w={class:"custom-container tip"},x=a("p",{class:"custom-container-title"},"TIP",-1),T=e("The "),I=a("code",null,"pm2 start",-1),P=e(" command can take more optional parameters, but only these two are relevant. If you want to see all the parameters available, you can check the documentation of pm2 "),M={href:"https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/",target:"_blank",rel:"noopener noreferrer"},S=e("here"),O=e("."),C=r(`<p>Once the process launches with pm2, you can run <code>pm2 monit</code> to monitor all console outputs from the processes started by pm2. This accounts for any <code>console.log()</code> in your code or outputted errors.</p><p>In a similar fashion to how you start the process, running <code>pm2 stop</code> will stop the current process without removing it from PM2&#39;s interface:</p><div class="language-bash ext-sh"><pre class="language-bash"><code>pm2 stop your-app-name.js
9</code></pre></div><h2 id="setting-up-booting-with-your-system" tabindex="-1"><a class="header-anchor" href="#setting-up-booting-with-your-system" aria-hidden="true">
9#</a> Setting up booting with your system</h2><p>Perhaps one of the more useful features of PM2 is being able to boot up with your Operating System. This feature will ensure that your bot processes will always be started after an (unexpected) reboot (e.g., after a power outage).</p><p>The initial steps differ per OS. In this guide, we&#39;ll cover those for Windows and Linux/macOS.</p><h3 id="initial-steps-for-windows" tabindex="-1"><a class="header-anchor" href="#initial-steps-for-windows" aria-hidden="true">#</a> Initial steps for Windows</h3>`,7),j=e("It is recommended to use "),A=a("code",null,"pm2-installer",-1),G=e(". Follow the steps over at their "),L={href:"https://github.com/jessety/pm2-installer",target:"_blank",rel:"noopener noreferrer"},N=a("code",null,"GitHub",-1),V=e("."),q=r(`<h3 id="initial-steps-for-linux-macos" tabindex="-1"><a class="header-anchor" href="#initial-steps-for-linux-macos" aria-hidden="true">#</a> Initial steps for Linux/macOS</h3><p>You&#39;ll need a start script, which you can get by running the following command:</p><div class="language-bash ext-sh"><pre class="language-bash"><code><span class="token comment"># Detects the available init system, generates the config, and enables startup system</span>
10pm2 startup
11</code></pre></div><p>Or, if you want to specify your machine manually, select one of the options with the command:</p><div class="language-bash ext-sh"><pre class="language-bash"><code>pm2 startup <span class="token punctuation">[</span>ubuntu <span class="token operator">|</span> ubuntu14 <span class="token operator">|</span> ubuntu12 <span class="token operator">|</span> centos <span class="token operator">|</span> centos6 <span class="token operator">|</span> arch <span class="token operator">|</span> oracle <span class="token operator">|</span> amazon <span class="token operator">|</span> macos <span class="token operator">|</span> darwin <span class="token operator">|</span> freesd <span class="token operator">|</span> systemd <span class="token operator">|</span> systemv <span class="token operator">|</span> upstart <span class="token operator">|</span> launchd <span class="token operator">|</span> rcd <span class="token operator">|</span> openrc<span class="token punctuation">]</span>
12</code></pre></div><p>The output of running one of the commands listed above will output a command for you to run with all environment variables and options configured.</p><p><strong>Example output for an Ubuntu user:</strong></p><div class="language-bash ext-sh"><pre class="language-bash"><code><span class="token punctuation">[</span>PM2<span class="token punctuation">]</span> You have to run this <span class="token builtin class-name">command</span> as root. Execute the following command:
13      <span class="token function">sudo</span> <span class="token function">su</span> <span class="token parameter variable">-c</span> &quot;env <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token environment constant">$PATH</span>:/home/user/.nvm/versions/node/v8.9/bin pm2 startup ubuntu <span class="token parameter variable">-u</span> user <span class="token parameter variable">--hp</span> /home/user
14</code></pre></div><p>After running that command, you can continue to the next step.</p><h3 id="saving-the-current-process-list" tabindex="-1"><a class="header-anchor" href="#saving-the-current-process-list" aria-hidden="true">#</a> Saving the current process list</h3><p>To save the current process list so it will automatically get started after a restart, run the following command:</p><div class="language-bash ext-sh"><pre class="language-bash"><code>pm2 save
15</code></pre></div><p>To disable this, you can run the following command:</p><div class="language-bash ext-sh"><pre class="language-bash"><code>pm2 unstartup
16</code></pre></div>`,14);function B(E,F){const t=o("CodeGroupItem"),p=o("CodeGroup"),i=o("OutboundLink");return c(),l(u,null,[h,m,g,b,s(p,null,{default:n(()=>[s(t,{title:"npm"},{default:n(()=>[f]),_:1}),s(t,{title:"yarn"},{default:n(()=>[_]),_:1}),s(t,{title:"pnpm"},{default:n(()=>[y]),_:1}),s(t,{title:"bun"},{default:n(()=>[v]),_:1})]),_:1}),k,a("div",w,[x,a("p",null,[T,I,P,a("a",M,[S,s(i)]),O])]),C,a("p",null,[j,A,G,a("a",L,[N,s(i)]),V]),q],64)}
16d.render=B;export{d as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.