Installation
Install the SecretStash Node module for secure variable management in any Node.js or TypeScript project.
The SecretStash Node module (@secret-stash/cli) can be used in two ways:
- Global CLI: Install globally and use the
secret-stashcommand from any directory. - Project dependency: Install locally and import the TypeScript/JavaScript API into your application for programmatic access.
Requirements
- Node.js 18 or higher
- A SecretStash API token and Application ID
Global Installation
Install the package globally to use the secret-stash CLI from anywhere on your machine:
Or run commands directly without installing using npx:
This package creates a ~/.secret-stash directory on your machine (or the path specified by the SECRET_STASH_KEY_DIR environment variable). Ensure this folder is secure as it contains the keys required to decrypt your environment variables. You can override this directory by setting the SECRET_STASH_KEY_DIR environment variable.
Initialize your device
After installing globally, initialize your device key:
This generates an RSA-4096 key pair and registers it with the SecretStash server.
Configure environment variables
Add the following to your project's .env file:
- API Token: Create a token in SecretStash by navigating to your profile settings and accessing the "Tokens" tab.
- Application ID: Create or select an Application in SecretStash and copy its ID from the dashboard.
Both the API token and Application ID are required. The module will throw an error if either is missing.
Quick start
Pull your environment's variables from SecretStash into your local .env file:
Push your local .env variables to SecretStash:
Project Dependency Installation
Install the package as a local dependency in your Node.js or TypeScript project:
Configure environment variables
Add the following to your project's .env file:
- API Token: Create a token in SecretStash by navigating to your profile settings and accessing the "Tokens" tab.
- Application ID: Create or select an Application in SecretStash and copy its ID from the dashboard.
Use the CLI via npx
When installed as a project dependency, run CLI commands via npx:
Use the programmatic API
Import the module directly into your TypeScript or JavaScript code for full programmatic control:
See Programmatic Usage for the full API reference.
Next Steps
- Explore all CLI commands in the commands reference.
- Learn about configuration options.
- Use the programmatic API for custom integrations.
- Set up CI/CD integration for automated pipelines.
Node module source code: https://github.com/dniccum/secret-stash-node