Use a private npm registry
Give every space on a stack the same private npm registry, with the token kept out of the space. Your team publishes packages to a private registry. You pick that registry on a stack, and each space started from it installs from there with plain npm install. The space holds a placeholder. Marshal swaps in the real token only on requests to the registry host.
Before you start
- You are an owner or admin. Owners and admins edit stacks.
- The registry is listed under Org Settings → npm registries. If it is not, add it there first, with its URL and the scopes it serves, for example
@acme. - The token is saved as an organization HTTP secret whose hosts cover the registry URL, for example
https://npm.acme.com/**. See Add an HTTP secret. - The stack’s network policy allows the registry host. The policy must allow it, not pass it through, so Marshal can add the token.
Link the token to the registry
- Open Org Settings → npm registries and edit the registry.
- Under HTTP secret for spaces, choose the secret that holds the token.
- Click Save.
Marshal checks that the secret belongs to your organization and that its hosts cover the registry URL. If they do not, the save names the problem.
Select the registry on the stack
- Open the stack and, in the left tree under Network, find npm registries.
- Tick the registries this stack should use. You can pick up to 20.
- A note under the list tells you when the stack’s network policy blocks a selected registry, or still allows public npm when you picked a default registry.
The selection applies the next time a space starts or resumes. A running space keeps what it had.
What a space gets
- A file at
~/.npmrcthat names each registry and its scopes. A default registry replaces public npm for unscoped packages. - A token line that points at an environment variable, never at the token itself. In the space,
echo $ACME_NPM_TOKENprints a placeholder. - In the Secrets tab, the linked secret is marked Managed by the stack.
Marshal writes ~/.npmrc only when the file is absent or it wrote the file itself. A file you created is never overwritten, and the start tells you it was left as it is. If the stack’s shell configuration already writes ~/.npmrc, the stack refuses to select registries until you remove that file there.
When an install fails
- The registry is blocked. Allow its host in the stack’s network policy, then start a new space.
- The token is not sent. Check that the HTTP secret’s hosts cover the registry URL and that the secret still exists. If it was deleted, the registry settings show its name and say so. Link another secret.
- Packages come from another host. Some registries serve package files from a second host. Add that host to the secret’s hosts and to the network policy.
- Your shell ignores the space’s environment. A shell that does not load the space’s environment cannot expand the variable in
~/.npmrc. Use a login shell, or runnpmfrom a tool call. - A repository has its own
.npmrc. npm reads it too. A repository file that sets a different registry or token takes precedence for that project.