DEV Community

Cover image for Environment Variables with PM2 + Infisical

Posted on


Environment Variables with PM2 + Infisical

Today, Infisical released docs for injecting environment variables into apps using PM2.

PM2 is a production process manager for Node.js applications. It allows you to keep your Node.js applications running, even after a system reboot, by managing the processes and automatically restarting them if they crash.

Infisical is a popular new open-source end-to-end encrypted secret manager. It helps teams keep their environment variables synced by injecting them into their apps and infrastructure.

There are a few steps to start syncing environment variables:

  1. Add your environment variables to Infisical.

  2. Install the Infisical CLI for your machine.

  3. Create a (bash or js) script at the root of your app. As an example, you can create a bash script called containing:

infisical run -- npm start

  1. Start your app with PM2:

pm2 start

That's all it takes to start pulling and injecting environment variables from Infisical into your app with P2M! With this integration, your team can now use PM2 + Infisical to start your app with the right set of environment variables at all times :)

Top comments (0)

11 Tips That Make You a Better Typescript Programmer


1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!