Skip to main content

CLI Reference

This page provides a complete reference for the Node SOPS command-line interface.

Command Structure

All Node SOPS commands follow this structure:

node-sops <command> [options]

Or when using npx:

npx node-sops <command> [options]

Global Options

These options can be used with any command:

OptionAliasDescription
--help-hShow help information
--version-vShow version information

Commands

init

Initializes a new encryption key for use with Node SOPS.

node-sops init [options]

Options:

OptionAliasDescriptionDefault
--key-path-kPath where the key should be stored.sops-key
--force-fOverwrite existing key if presentfalse

Examples:

# Create a new key in the default location
node-sops init

# Create a new key in a custom location
node-sops init --key-path ./config/encryption.key

# Force overwrite an existing key
node-sops init --force

encrypt

Encrypts a plaintext file containing secrets.

node-sops encrypt [options]

Options:

OptionAliasDescriptionDefault
--in-iPath to input file (required)-
--out-oPath to output file (required)-
--key-path-kPath to the encryption key.sops-key

Examples:

# Encrypt a YAML file
node-sops encrypt -i secrets.yaml -o secrets.enc.json

# Encrypt a JSON file
node-sops encrypt -i secrets.json -o secrets.enc.json

# Use a custom key path
node-sops encrypt -i secrets.yaml -o secrets.enc.json -k ./config/encryption.key

decrypt

Decrypts an encrypted file to its original plaintext form.

node-sops decrypt [options]

Options:

OptionAliasDescriptionDefault
--in-iPath to input file (required)-
--out-oPath to output file (required)-
--key-path-kPath to the encryption key.sops-key
--format-fOutput format (yaml or json)Inferred from output file extension

Examples:

# Decrypt to a YAML file
node-sops decrypt -i secrets.enc.json -o secrets.yaml

# Decrypt to a JSON file
node-sops decrypt -i secrets.enc.json -o secrets.json

# Explicitly specify the output format
node-sops decrypt -i secrets.enc.json -o secrets.txt -f yaml

view

Display the decrypted content of an encrypted file without writing it to disk.

node-sops view [options]

Options:

OptionAliasDescriptionDefault
--in-iPath to input file (required)-
--key-path-kPath to the encryption key.sops-key
--format-fOutput format (json, yaml, or pretty)pretty

Examples:

# View with pretty formatting
node-sops view -i secrets.enc.json

# View as YAML
node-sops view -i secrets.enc.json -f yaml

# View as JSON
node-sops view -i secrets.enc.json -f json

get

Retrieve a specific value from an encrypted file using dot notation.

node-sops get [options]

Options:

OptionAliasDescriptionDefault
--in-iPath to input file (required)-
--key-kDot-notation path to the value (required)-
--key-path-pPath to the encryption key.sops-key

Examples:

# Get an API key
node-sops get -i secrets.enc.json -k data.api.key

# Get a nested database password
node-sops get -i secrets.enc.json -k data.database.password

rotate

Re-encrypt a file with a new initialization vector. The content remains the same, but the encrypted file will be different.

node-sops rotate [options]

Options:

OptionAliasDescriptionDefault
--in-iPath to input file (required)-
--out-oPath to output fileSame as input
--key-path-kPath to the encryption key.sops-key

Examples:

# Rotate the encryption in place
node-sops rotate -i secrets.enc.json

# Rotate to a new file
node-sops rotate -i secrets.enc.json -o new-secrets.enc.json

Error Codes

The CLI will exit with the following error codes when encountering issues:

CodeDescription
1General error (invalid arguments, etc.)
2File not found
3Permission denied
4Encryption/decryption error
5Invalid key file