Development version

This documentation is for a Forgejo version which is not yet released.

To read the documentation for the released version of Forgejo, navigate to the latest version.

npm Package Registry

Publish npm packages for your user or organization.

Requirements

To work with the npm package registry, you need Node.js coupled with a package manager such as Yarn or npm itself.

The registry supports scoped and unscoped packages.

The following examples use the npm tool with the scope @test and username testuser.

Configuring the package registry

To register the package registry with npm, you need to configure a new package source and provide the package owner’s token.

npm config set {scope}:registry https://forgejo.example.com/api/packages/{owner}/npm/
npm config set -- '//forgejo.example.com/api/packages/{owner}/npm/:_authToken' "{owner_token}"
Note

In the example below (npm config set -- '//forgejo...) the leading scheme, https:, is intentionally missing. It must not be included. The following is incorrect: npm config set -- 'https://forgejo... as the npm config only uses a URI fragment in the config. See examples.

ParameterDescription
scopeThe scope of the packages.
ownerThe owner of the package.
tokenThe owner’s personal access token.

For example:

npm config set @test:registry https://forgejo.example.com/api/packages/testuser/npm/
npm config set -- '//forgejo.example.com/api/packages/testuser/npm/:_authToken' "{personal_access_token}"

or without scope:

npm config set registry https://forgejo.example.com/api/packages/testuser/npm/
npm config set -- '//forgejo.example.com/api/packages/testuser/npm/:_authToken' "{personal_access_token}"

Publish a package

When publishing a package, npm uses configs and defaults if the arguments are not specified in the command or project. The following commands demonstrate a default publish, publishing to a specific registry, and a specific scope and registry:

npm publish
npm publish --registry={SERVER_URL}/api/packages/{owner}/npm/
npm publish --scope=@{scope} --registry={SERVER_URL}/api/packages/{owner}/npm/

You cannot publish a package if a package of the same name and version already exists. First, you must delete that version of the existing package, either in UI at SERVER_URL/OWNER/-/packages/npm/PACKAGE_NAME/PACKAGE_VERSION/settings or unpublish in CLI.

Unpublish a package

Delete a package by running the following command:

npm unpublish {package_name}[@{package_version}]
ParameterDescription
package_nameThe package name.
package_versionThe package version.

For example:

npm unpublish @test/test_package
npm unpublish @test/test_package@1.0.0

Note: This behavior is different than the public npm repository. Once you delete or unpublish a package, you can re-publish a package with the same name and version immediately.

Install a package

To install a package from the package registry, execute the following command:

npm install {package_name}
ParameterDescription