mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
feat(guide): port legacy guide (#10938)
* feat: initial attempt at porting legacy guide * feat: completion of legacy guide backport * chore: lockfile shenanigans * fix: handle svgs * fix: replace svg with mermaid integration * chore: format * chore: remove unnecssary bullet * chore: cleanup code highlights * chore: explicit return * chore: move display components after interactive components in sidebar * chore: voice * top link should be installation * add docs link to sidebar * feat: subguide-based accent styles * chore: don't list faq twice * chore: mention display components in interactive components * fix: remove unoccs/order rule from guide * chore: redirect to legacy guide instead of /guide root * refactor: use `<kbd>` * refactor: more kbd use * Update apps/guide/content/docs/legacy/app-creation/handling-events.mdx Co-authored-by: Naiyar <137700126+imnaiyar@users.noreply.github.com> * chore: fix typos Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> * chore: fix typos * chore: fix links regarding secret stores across coding platforms * chore: fix typo * chore: link node method directly Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> * chore: typos Co-authored-by: Vlad Frangu <me@vladfrangu.dev> * chore: typo Co-authored-by: Vlad Frangu <me@vladfrangu.dev> * fix: prevent v14 changes from being listed twice * chore: prefer relative links * chore: missed link conversion * chore: missed link conversion * chore: fix link * chore: remove legacy code highlight markers * chore: rephrase and extend contributing guidelines * feat(setup): suggest cli flag over dotenv package * chore: move introduction in sidebar better navigation experience if the 'next page' in intro refers to getting started vs. updating/faq * fix: replace outdated link * fix: update voice dependencies * chore: update node install instructions * fix: list in missing access callout * chore: match bun env file format * chore: restore ffmpeg disclaimer * fix: lockfile conflict * chore: action row typo Co-authored-by: Vlad Frangu <me@vladfrangu.dev> * chore: no longer use at-next for pino --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> Co-authored-by: Naiyar <137700126+imnaiyar@users.noreply.github.com> Co-authored-by: Vlad Frangu <me@vladfrangu.dev>
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
---
|
||||
title: Package scripts
|
||||
---
|
||||
|
||||
## Setting up package.json scripts
|
||||
|
||||
An easy way to run scripts like a script to start your bot, a script to lint your bot's files, or whatever scripts you use is by storing them in your `package.json` file. After you store these scripts in your `package.json` file, you can run the `start` script to start your bot or the `lint` script to lint your code for errors.
|
||||
|
||||
```sh tab="npm"
|
||||
npm run start
|
||||
npm run lint
|
||||
```
|
||||
|
||||
```sh tab="yarn"
|
||||
yarn run start
|
||||
yarn run lint
|
||||
```
|
||||
|
||||
```sh tab="pnpm"
|
||||
pnpm run start
|
||||
pnpm run lint
|
||||
```
|
||||
|
||||
```sh tab="bun"
|
||||
bun run start
|
||||
bun run lint
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
<Callout>
|
||||
Before getting started, you'll need to have a `package.json` file. If you don't have a `package.json` file yet, you can run the following command in the console to generate one.
|
||||
|
||||
```sh tab="npm"
|
||||
npm init -y
|
||||
```
|
||||
|
||||
```sh tab="yarn"
|
||||
yarn init -y
|
||||
```
|
||||
|
||||
```sh tab="pnpm"
|
||||
pnpm init
|
||||
```
|
||||
|
||||
```sh tab="bun"
|
||||
bun init -y
|
||||
```
|
||||
|
||||
</Callout>
|
||||
|
||||
If you haven't touched your `package.json` file yet (excluding installing dependencies), your `package.json` file should look similar to the following:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"name": "my-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "A Discord bot!",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
```
|
||||
|
||||
Let's zoom in more. Below `main`, you'll see `scripts`. You can specify your scripts there. In this guide, we'll show how to start and lint your bot using a `package.json` script.
|
||||
|
||||
## Adding your first script
|
||||
|
||||
<Callout>
|
||||
We'll assume you have finished the [creating your app](../app-creation/project-setup) section of the guide. If you
|
||||
haven't, ensure to follow it first!
|
||||
</Callout>
|
||||
|
||||
Over at your `package.json` file, add the following line to the `scripts`:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"name": "my-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "A Discord bot!",
|
||||
"main": "index.js",
|
||||
"scripts": { // [!code focus:5]
|
||||
"test": "echo \"Error: no test specified\" && exit 1" // needs a comma // [!code --]
|
||||
"test": "echo \"Error: no test specified\" && exit 1", // [!code ++]
|
||||
"start": "node ." // [!code ++]
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
```
|
||||
|
||||
<Callout>
|
||||
The `node .` script will run the file you have specified at the `main` entry in your `package.json` file. If you don't
|
||||
have it set yet, make sure to select your bot's main file as `main`!
|
||||
</Callout>
|
||||
|
||||
Now, whenever you run the `start` script in your bot's directory, it will run the `node .` command.
|
||||
|
||||
```sh tab="npm"
|
||||
npm run start
|
||||
```
|
||||
|
||||
```sh tab="yarn"
|
||||
yarn run start
|
||||
```
|
||||
|
||||
```sh tab="pnpm"
|
||||
pnpm run start
|
||||
```
|
||||
|
||||
```sh tab="bun"
|
||||
bun run start
|
||||
```
|
||||
|
||||
Let's create another script to lint your code via the command line. Add the following line to your scripts:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"name": "my-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "A Discord bot!",
|
||||
"main": "index.js",
|
||||
"scripts": { // [!code focus:6]
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node ." // needs a comma // [!code --]
|
||||
"start": "node .", // [!code ++]
|
||||
"lint": "eslint ." // [!code ++]
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
```
|
||||
|
||||
Now, whenever you run the `lint` script, ESLint will lint your `index.js` file.
|
||||
|
||||
```sh tab="npm"
|
||||
npm run lint
|
||||
```
|
||||
|
||||
```sh tab="yarn"
|
||||
yarn run lint
|
||||
```
|
||||
|
||||
```sh tab="pnpm"
|
||||
pnpm run lint
|
||||
```
|
||||
|
||||
```sh tab="bun"
|
||||
bun run lint
|
||||
```
|
||||
|
||||
Your `package.json` file should now look similar to the following:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "A Discord bot!",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node .",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
```
|
||||
|
||||
And that's it! You can always add more scripts now, running them with:
|
||||
|
||||
```sh tab="npm"
|
||||
npm run <script-name>
|
||||
```
|
||||
|
||||
```sh tab="yarn"
|
||||
yarn run <script-name>
|
||||
```
|
||||
|
||||
```sh tab="pnpm"
|
||||
pnpm run <script-name>
|
||||
```
|
||||
|
||||
```sh tab="bun"
|
||||
bun run <script-name>
|
||||
```
|
||||
|
||||
<Cards>
|
||||
<Card title="Package Scripts" href="https://docs.npmjs.com/cli/v7/using-npm/scripts">
|
||||
Package scripts allow some more configuration (like pre-, post- and lifecycle scripts) than we can cover in this
|
||||
guide. Check out the official documentation on for more information.
|
||||
</Card>
|
||||
</Cards>
|
||||
113
apps/guide/content/docs/legacy/improving-dev-environment/pm2.mdx
Normal file
113
apps/guide/content/docs/legacy/improving-dev-environment/pm2.mdx
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
title: PM2
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
## Installation
|
||||
|
||||
You can install PM2 via the following command:
|
||||
|
||||
```sh tab="npm"
|
||||
npm install --global pm2
|
||||
```
|
||||
|
||||
```sh tab="yarn"
|
||||
yarn global add pm2
|
||||
```
|
||||
|
||||
```sh tab="pnpm"
|
||||
pnpm add --global pm2
|
||||
```
|
||||
|
||||
```sh tab="bun"
|
||||
bun add --global pm2
|
||||
```
|
||||
|
||||
## Starting your app
|
||||
|
||||
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:
|
||||
|
||||
```sh
|
||||
pm2 start your-app-name.js
|
||||
```
|
||||
|
||||
### Additional notes
|
||||
|
||||
The `pm2 start` script allows for more optional command-line arguments.
|
||||
|
||||
- `--name`: This allows you to set the name of your process when listing it up with `pm2 list` or `pm2 monit`:
|
||||
|
||||
```sh
|
||||
pm2 start your-app-name.js --name "Some cool name"
|
||||
```
|
||||
|
||||
- `--watch`: This option will automatically restart your process as soon as a file change is detected, which can be useful for development environments:
|
||||
|
||||
```bash
|
||||
pm2 start your-app-name.js --watch
|
||||
```
|
||||
|
||||
<Callout>
|
||||
The `pm2 start` 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
|
||||
[here](https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/).
|
||||
</Callout>
|
||||
|
||||
Once the process launches with pm2, you can run `pm2 monit` to monitor all console outputs from the processes started by pm2. This accounts for any `console.log()` in your code or outputted errors.
|
||||
|
||||
In a similar fashion to how you start the process, running `pm2 stop` will stop the current process without removing it from PM2's interface:
|
||||
|
||||
```sh
|
||||
pm2 stop your-app-name.js
|
||||
```
|
||||
|
||||
## Setting up booting with your system
|
||||
|
||||
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).
|
||||
|
||||
The initial steps differ per OS. In this guide, we'll cover those for Windows and Linux/macOS.
|
||||
|
||||
### Initial steps for Windows
|
||||
|
||||
It is recommended to use `pm2-installer`. Follow the steps over at their [`GitHub`](https://github.com/jessety/pm2-installer).
|
||||
|
||||
### Initial steps for Linux/macOS
|
||||
|
||||
You'll need a start script, which you can get by running the following command:
|
||||
|
||||
```sh
|
||||
# Detects the available init system, generates the config, and enables startup system
|
||||
pm2 startup
|
||||
```
|
||||
|
||||
Or, if you want to specify your machine manually, select one of the options with the command:
|
||||
|
||||
```sh
|
||||
pm2 startup [ubuntu | ubuntu14 | ubuntu12 | centos | centos6 | arch | oracle | amazon | macos | darwin | freesd | systemd | systemv | upstart | launchd | rcd | openrc]
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
**Example output for an Ubuntu user:**
|
||||
|
||||
```
|
||||
[PM2] You have to run this command as root. Execute the following command:
|
||||
sudo su -c "env PATH=$PATH:/home/user/.nvm/versions/node/v8.9/bin pm2 startup ubuntu -u user --hp /home/user
|
||||
```
|
||||
|
||||
After running that command, you can continue to the next step.
|
||||
|
||||
### Saving the current process list
|
||||
|
||||
To save the current process list so it will automatically get started after a restart, run the following command:
|
||||
|
||||
```sh
|
||||
pm2 save
|
||||
```
|
||||
|
||||
To disable this, you can run the following command:
|
||||
|
||||
```sh
|
||||
pm2 unstartup
|
||||
```
|
||||
Reference in New Issue
Block a user