# Deploying

## Deploying as a Standalone Node.js Application

**Step 1: Build the Project**

```bash
npm run build
```

**Step 2: Start the Server**

Once the project is built, you can start the server using:

```bash
node build/server/main.js
```

{% hint style="info" %}
For production deployments, it's recommended to use a process manager like PM2 to ensure robustness and ease of management.
{% endhint %}

**Step 3: Using PM2 (Recommended)**

Install PM2 globally if you haven't already:

```bash
npm install -g pm2
```

Now, start your MagicJS application using PM2:

```
pm2 start build/server/main.js --name my-magic-app
```

{% hint style="info" %}
This will start your MagicJS application as a background process, and PM2 will handle logging, monitoring, and automatic restarts.
{% endhint %}

## Deploying as a Container

Documentation for deploying MagicJS as a container is currently under development and will be available soon. Stay tuned for updates!

## Some of the best practices to consider before deploying.

* **Environment Configuration**: Make sure to configure your environment variables appropriately for your production environment.
* **Security Considerations**: Implement security best practices, including proper firewall configurations and secure connection settings.
* **Monitoring**: Use monitoring tools to keep an eye on your application's performance and health.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://skyslit.gitbook.io/magicjs/deploying.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
