npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sync-cf-workers-secret

v0.0.1

Published

Sync .env values to Cloudflare Workers secrets in one command — a tiny CLI wrapping wrangler secret bulk, with skip-missing and key renaming for multi-environment deploys

Readme

sync-cf-workers-secret

Sync .env values to Cloudflare Workers secrets in one command. A tiny CLI and Node.js API that wraps wrangler secret bulk: pick the keys you want, and it uploads only the ones present in your .env file — handy as the last step of a deploy script or CI/CD pipeline (GitHub Actions, etc.), and for multi-environment setups (staging, preview, production) where each environment needs different values under the same secret name.

Why

Worker secrets (AUTH_SECRET, DATABASE_URL, …) live on Cloudflare, not in your code, so deploying a Worker does not update them. Running wrangler secret put once per secret is tedious and easy to forget once you have more than a handful. sync-cf-workers-secret turns that into one line, and handles two things wrangler doesn't do for you:

  1. Missing values are skipped, not fatal. If a key is absent from .env (e.g. on a local machine), it prints a warning to stderr and moves on. If nothing is left to sync, it exits with code 0 so your deploy script keeps going.
  2. Rename on the way in (TARGET=SOURCE). Upload the .env value SOURCE under the secret name TARGET. Your Worker code reads one name, while each environment feeds it a different value.

Install

npm install -D sync-cf-workers-secret
# or
pnpm add -D sync-cf-workers-secret

Requirements:

  • Node.js 20.12+ (uses util.parseEnv)
  • wrangler available through npx, and logged in (wrangler login or CLOUDFLARE_API_TOKEN)

Usage

# Upload AUTH_SECRET and DATABASE_URL from .env as secrets with the same names
sync-cf-workers-secret --env .env AUTH_SECRET DATABASE_URL

# Target a wrangler environment (runs `wrangler secret bulk --env staging`)
sync-cf-workers-secret --env .env --wrangler-env staging AUTH_SECRET API_KEY

# Rename: upload the .env value STAGING_DATABASE_URL as the secret DATABASE_URL
sync-cf-workers-secret --env .env --wrangler-env staging \
  DATABASE_URL=STAGING_DATABASE_URL API_KEY

As a deploy step in package.json:

{
  "scripts": {
    "deploy": "wrangler deploy && pnpm sync-secrets",
    "sync-secrets": "sync-cf-workers-secret --env .env AUTH_SECRET DATABASE_URL"
  }
}

Arguments

| Form | Meaning | | --- | --- | | KEY | Upload the .env value KEY as the secret KEY | | TARGET=SOURCE | Upload the .env value SOURCE as the secret TARGET |

Options

| Option | Description | | --- | --- | | -e, --env <path> | Path to the .env file (default: .env) | | --wrangler-env <name> | Passed to wrangler secret bulk --env <name> to target that environment's Worker | | -h, --help | Show help |

⚠️ -e/--env is the path to your .env file, not a wrangler environment. Because wrangler's own -e means "environment", the wrangler environment is accepted only through the separate --wrangler-env flag.

API

import { syncSecrets } from "sync-cf-workers-secret";

syncSecrets(".env", {
  keys: ["AUTH_SECRET", "DATABASE_URL=STAGING_DATABASE_URL"],
  wranglerEnv: "staging", // optional
});
type SyncSecretsInput = { keys: string[]; wranglerEnv?: string };
function syncSecrets(envPath: string, input: SyncSecretsInput): void;

syncSecrets runs synchronously and calls process.exit when there is nothing to sync (code 0) or when wrangler fails (wrangler's exit code).

How it works

  • Reads .env with Node's built-in util.parseEnv — no dotenv dependency.
  • Writes the collected values to a temporary JSON file (mode 0600, in os.tmpdir()), runs npx wrangler secret bulk <file>, and deletes the file afterwards, even on failure.
  • If the .env file itself is missing, it warns and exits with code 0.

License

MIT