Configure a private registry for an organization scope with bun install

You can configure private registries in .npmrc or bunfig.toml. Both work; we recommend bunfig.toml for its Bun-specific options.

To configure a registry for a particular npm scope:

bunfig.toml
[install.scopes]
# as a string
"@myorg1" = "https://username:password@registry.myorg.com/"

# as an object with username/password
# you can reference environment variables
"@myorg2" = {
  username = "myusername",
  password = "$npm_pass",
  url = "https://registry.myorg.com/"
}

# as an object with token
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }

Your bunfig.toml can reference environment variables. bun install automatically loads environment variables from .env.production.local, .env.local, .env.production, and .env. When BUN_ENV (or, if it is not set, NODE_ENV) is development, it reads .env.development.local and .env.development in place of the two production files. It does not read .env.test. To load a specific file, pass --env-file. To load no file, pass --no-env-file. See Environment variables.

bunfig.toml
[install.scopes]
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }

See bun install.