Hanzo
PlatformHanzo KMSIntegrationsPlatforms

PM2

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

Prerequisites:

Initialize Hanzo KMS for your Node.js app

# navigate to the root of your of your project
cd /path/to/project

# then initialize kms
kms init

Create a bash or js script

kms run -- npm start
const spawn = require("child_process").spawn;

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

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

Start your application as usual but with the script

pm2 start kms-run.sh
pm2 start kms-run.js

How is this guide?

Last updated on

On this page