Store API keys and credentials for your worker securely.
Secrets let your Notion Workers use API keys, tokens, client secrets, webhook signing secrets, and other credentials without committing those values to your source code.Notion encrypts worker secrets at rest and exposes them as environment variables at runtime. In your worker code, read them from process.env.
const apiKey = process.env.OPENWEATHER_API_KEY;
Never commit .env files or any type of secret to source control. Worker
projects created from the template include .env and .env.* in .gitignore
by default.
When you run a worker locally, use a .env file to provide the same environment variables that the hosted worker receives.Pull remote secrets into .env:
ntn workers env pull
Or write to a different file:
ntn workers env pull --file=.env.local
If the file already exists, pull preserves comments, blank lines, and local-only keys. It updates keys that also exist remotely, then appends new remote keys.For non-interactive scripts, add --yes to skip the confirmation prompt:
ntn workers env pull --yes
Treat any pulled .env file as sensitive. Confirm that the file is ignored by Git
before you pull secrets into a project.
If you’ve added secrets locally to .env, push them to the hosted worker:
ntn workers env push
Or push a different file:
ntn workers env push --file=.env.local
push adds new local keys and updates changed local keys. It does not remove keys that exist only in the remote worker environment.For non-interactive scripts, add --yes:
When you run these commands inside a worker project, the CLI reads the worker ID from workers.json. To manage a different worker, pass its worker ID.For set and unset, use --worker-id: