opx

OPX

The most secure way to run NodeJS apps locally!

crates.io badge build status badge license badge

Overview

This is a CLI meant to enhance the native 1Passwords native CLI (op) simplifying the developer experience.

While you can run the following 1Password op run CLI there is a bit of manual effort to pass the additional flags where each one of your .env files is located.

op run --env-file=.env -- pnpm dev

With opx it will scan you current working directory for any .env files and load them as variadic --env-file argument(s).

Installing

Ensure you have installed an configured the 1Password CLI. Then you can Install the opx CLI utility with cargo.

cargo install opx

Usage

You need to have at least one .env file in any folder of your project and it must reference a secret from 1Password.

APPLE_ID="op://overlayed/apple_id/credential"

Start your application to inject the secrets as environment variables.

opx

It will check packageManager definition and use that to start your app. The default package manager is npm and the default script is dev. You can override the default script with opx.defaultScript in package.json.

{
  "opx": {
    "defaultScript": "start"
  }
}

If your package script points back at opx, use opx.defaultCommand to run the underlying command directly.

{
  "scripts": {
    "dev": "opx"
  },
  "opx": {
    "defaultCommand": "npx next dev"
  }
}

defaultCommand is passed directly after op run --, so the example above runs op run -- npx next dev.

Because defaultCommand runs directly, it does not automatically add your Node project’s local node_modules/.bin directory to PATH. If you want to run a project-local binary, use your package runner, such as npx, pnpm exec, or yarn exec.

For exact argument control, defaultCommand can also be an array:

{
  "opx": {
    "defaultCommand": ["next", "dev", "--hostname", "0.0.0.0"]
  }
}

defaultCommand is parsed into command arguments; it does not run through a shell. For shell features like &&, pipes, or redirects, use an explicit shell command such as ["sh", "-c", "next dev && echo done"].

You can run any script in your applications package.json with opx <args>.

Example running this demo application.

$ opx
[OPX] Using package manager pnpm 
[OPX] Forcing terminal colors with FORCE_COLOR=1
[OPX] op run \
        --env-file=apps/demo/.env \
        --env-file=apps/other-app/.env -- pnpm dev
demo:dev: Hello this is a sample app that uses a secret from 1password cli
demo:dev: Secret is: <concealed by 1Password>
other-app:dev: Hello this is a sample app that uses a secret from 1password cli
other-app:dev: Secret is: <concealed by 1Password>