> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poplock.scyne.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install and start the PopLock API as a systemd service.

The PopLock API is a single file with no npm dependencies. Installation is a copy-and-configure process.

## Prerequisites

* Node.js available at `/usr/bin/node`
* `systemd` for service management
* `openssl` for key generation

## Steps

<Steps>
  <Step title="Copy the application file">
    Copy the script to your system binaries directory:

    ```bash theme={null}
    sudo cp poplock-api.js /usr/local/bin/poplock-api.js
    ```
  </Step>

  <Step title="Set up the config file">
    Copy the config template and lock down its permissions:

    ```bash theme={null}
    sudo cp poplock-api.conf /etc/poplock-api.conf
    sudo chmod 600 /etc/poplock-api.conf
    ```

    <Warning>
      The config file contains your API key. Keep permissions set to `600` so only root can read it. Wider permissions expose your key to all local users.
    </Warning>
  </Step>

  <Step title="Generate an API key">
    Generate a secure 32-byte hex string:

    ```bash theme={null}
    openssl rand -hex 32
    ```

    Open the config file in a text editor and replace `REPLACE_WITH_YOUR_SECRET_KEY` with the generated string:

    ```bash theme={null}
    sudo nano /etc/poplock-api.conf
    ```

    The config file format is:

    ```text theme={null}
    # /etc/poplock-api.conf
    API_KEY=your_secret_key_here
    PORT=6767
    ```

    <Tip>
      The port can be changed by setting `PORT=` in `/etc/poplock-api.conf` or by setting the `PORT` environment variable before starting the service. The default is `6767`.
    </Tip>
  </Step>

  <Step title="Install the systemd service">
    Before copying, open `poplock-api.service` and update the `User` and `Group` fields to match the system user that owns the Minecraft server directory:

    ```ini poplock-api.service theme={null}
    [Service]
    User=your_username
    Group=your_username
    ```

    Then copy the unit file, reload systemd, and enable the service so it starts on boot:

    ```bash theme={null}
    sudo cp poplock-api.service /etc/systemd/system/poplock-api.service
    sudo systemctl daemon-reload
    sudo systemctl enable --now poplock-api
    ```
  </Step>

  <Step title="Verify it's running">
    Check the service status:

    ```bash theme={null}
    sudo systemctl status poplock-api
    ```

    You should see `active (running)` in the output. The API will be listening on `http://0.0.0.0:6767`.
  </Step>
</Steps>
