mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-10 07:58:15 -05:00
53 lines
1008 B
Plaintext
53 lines
1008 B
Plaintext
---
|
|
title: "PM2"
|
|
description: "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](/cli/overview)
|
|
|
|
## Initialize Infisical for your Node.js app
|
|
|
|
```bash
|
|
# navigate to the root of your of your project
|
|
cd /path/to/project
|
|
|
|
# then initialize infisical
|
|
infisical init
|
|
```
|
|
|
|
## Create a bash or js script
|
|
|
|
<CodeGroup>
|
|
|
|
```bash infisical-run.sh
|
|
infisical run -- npm start
|
|
```
|
|
|
|
```js infisical-run.js
|
|
const spawn = require("child_process").spawn;
|
|
|
|
const infisical = spawn("infisical", ["run", "--", "npm", "start"]);
|
|
|
|
infisical.stdout.on("data", (data) => console.log(`${data}`));
|
|
infisical.stderr.on("data", (data) => console.error(`${data}`));
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
## Start your application as usual but with the script
|
|
|
|
<CodeGroup>
|
|
|
|
```bash infisical-run.sh
|
|
pm2 start infisical-run.sh
|
|
```
|
|
|
|
```bash infisical-run.js
|
|
pm2 start infisical-run.js
|
|
```
|
|
|
|
</CodeGroup>
|