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

# Inject secrets into a PM2 app

> How to use Infisical to inject environment variables and secrets with PM2 into a Node.js app.

Prerequisites:

* Set up and add envars to [Infisical Cloud](https://app.infisical.com)
* [Install the CLI](https://infisical.com/docs/cli/install.md)

## Initialize Infisical for your Node.js app

```bash theme={"dark"}
# navigate to the root of your of your project
cd /path/to/project

# then initialize infisical
infisical init
```

## Create a bash or js script

```bash infisical-run.sh theme={"dark"}
infisical secrets-manager run -- npm start
```

```js infisical-run.js theme={"dark"}
const spawn = require("child_process").spawn;

const infisical = spawn("infisical", ["sm", "run", "--", "npm", "start"]);

infisical.stdout.on("data", (data) => console.log(`${data}`));
infisical.stderr.on("data", (data) => console.error(`${data}`));
```

## Start your application as usual but with the script

```bash infisical-run.sh theme={"dark"}
pm2 start infisical-run.sh
```

```bash infisical-run.js theme={"dark"}
pm2 start infisical-run.js
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.