npm packages (JavaScript, TypeScript)
Publish a JavaScript or TypeScript package to Zaryn with npm, install it with npm, pnpm or yarn, and keep it private. Every step explained.
Search for a command to run…
Publish a JavaScript or TypeScript package to Zaryn with npm, install it with npm, pnpm or yarn, and keep it private. Every step explained.
Only want npm installs to be faster or to work when npmjs.com is out of reach? See the npm mirror.
npm installs JavaScript packages. It can send one scope (the @name/ part of a package name) to a different registry than the rest, which is how Zaryn fits in: your @you/... packages come from Zaryn, everything else still comes from npmjs.com.
Create a token on Packages (Create a publish token). Then put these two lines in a file called .npmrc, either in your project's folder or in your home folder (~/.npmrc) for every project:
@your-username:registry=https://api.zaryn.xyz/v1/packages/npm///api.zaryn.xyz/v1/packages/npm/:_authToken=YOUR_TOKEN@your-username/ live on Zaryn.${NPM_TOKEN} from the environment if you write _authToken=${NPM_TOKEN}.Use your Zaryn username, or the name of an organization you own or administer, as the scope.
In package.json, give the package a scoped name and a version:
{ "name": "@your-username/hello", "version": "0.1.0", "main": "index.js"}npm publish --access publicWithout --access public, npm asks for a private package (that's npm's rule for scoped names), which needs Premium. To publish a fix, raise version and publish again; a published version can't be replaced.
With the .npmrc lines in place, install it like any other package:
npm install @your-username/hellopnpm add @your-username/helloyarn add @your-username/helloAny commit of a repository with a package.json installs without publishing: the repository's install tab (next to the clone commands) gives the line:
npm install https://zaryn.xyz/api/v1/repos/<owner>/<repo>/branches/main/archive/<commit>.tar.gzIt pins that exact commit, in package.json too.
npm publish without --access public creates a private package; you can also switch an existing one on its page (Make private). Only you, or members of the organization that owns it, can see or install it, using the same .npmrc token.
| npm says | What it means | Fix |
|---|---|---|
E401 | no token, or a wrong one | check the _authToken line in .npmrc |
E403 "you can only publish under your own @username…" | the scope isn't yours | use your username or your organization's name |
E402 "Private packages are a Premium feature" | a scoped publish without --access public | add --access public, or upgrade |
E404 when installing an unscoped package | npm asked Zaryn for a package that lives on npmjs.com | only map your scope to Zaryn, as above |
E409 "already published" | versions can't be replaced | raise version |
Zaryn speaks npm's registry protocol: the package document npm reads (versions, dist-tags, dependencies) and the .tgz files, each with its sha512 integrity value, which npm checks on every install.