CLI

Environment files

prepare env creates each app's .env from its .env.example and fills in the secrets a first run needs.

A new project needs a .env next to each app before it runs, with a few secrets that nobody should type by hand. prepare env makes them. The starters run it as pnpm prepare:env.

prepare env

pnpx @frigear-nu/cli prepare env [--dry-run] [--cwd <dir>]
ArgumentDefaultPurpose
--dry-runPrint what would change and write nothing.
--cwdthe current directoryWhere to start; the command works on the nearest workspace root above it.

For each apps/*/.env.example and packages/*/.env.example, it:

  1. Copies .env.example to .env next to it, unless .env exists. New files are only readable by you (0600).
  2. Fills in the secrets below whose line is empty (KEY=, KEY="" or KEY=''), in a new or an existing .env.

A value that is already set is never changed, so running it again is safe: after a git pull that adds a variable to an example, add the line to your .env with no value and run it again.

apps/web/.env: created from .env.example; generated NUXT_APP_SECRET
apps/mobile/.env: up to date, nothing changed

Built-in secrets

VariableGeneratorUsed by
NUXT_APP_SECRETrandom:32Nuxt's appSecret; nuxt-auth-utils seals the session cookie with it.
NUXT_OAUTH_SERVER_PRIVATE_KEYrsa@frigear-nu/oauth-server signs its tokens with it.

Your own secrets

Add secrets, or change where it looks, in the frigear field of the root package.json, next to your custom platforms:

package.json
{
  "frigear": {
    "env": {
      "secrets": {
        "NUXT_WEBHOOK_SECRET": "hex:32",
        "NUXT_DEVICE_ID": "uuid",
        "NUXT_OAUTH_SERVER_PRIVATE_KEY": false
      },
      "dirs": ["apps", "packages", "services"]
    }
  }
}
FieldPurpose
secretsVariable name → generator. A built-in's name replaces its generator; false turns it off.
dirsThe folders whose direct subfolders are searched for .env.example. Default: apps and packages.

The generators:

GeneratorValue
random:<bytes>Random bytes, base64 (random:32 gives 44 characters).
hex:<bytes>Random bytes, hex (hex:32 gives 64 characters).
uuidA random UUID.
rsaA 2048-bit PKCS#8 RSA private key on one line with \n escapes, in double quotes.

An unknown generator stops the command with the variable's name, before anything is written for that file.

From code

For a value no generator covers, call prepareEnv from a script of your own and pass a function:

scripts/prepare-env.ts
import { prepareEnv, describeEnvResult } from '@frigear-nu/cli'

const results = await prepareEnv({
  root: process.cwd(),
  secrets: {
    NUXT_PUBLIC_DEV_PORT: () => String(3000 + Math.floor(Math.random() * 1000)),
  },
})
for (const result of results) console.log(describeEnvResult(result))

secrets is applied after the built-ins and frigear.env, so it can add, replace ('hex:16' or a function) or turn off (false) any of them. See From code for every option.

Projects with their own script

Projects made from a starter before this command shipped have a scripts/prepare-env.mjs. It does the same thing, so it keeps working. To switch, delete it and set the root script:

package.json
{
  "scripts": {
    "prepare:env": "pnpx @frigear-nu/cli prepare env"
  }
}

If you added secrets to your copy of the script, move them to frigear.env.secrets.

Next steps

Copyright © 2026