Pushing npm Packages to Gitea

Last modified by DevOps-as-a-Service Operator on 2025/02/05 11:33

This step-by-step guide outlines how to push your npm packages to a Gitea registry. 

Requirements

  • A package is prepared for publication.
  • npm (Node Package Manager) is installed on the user's machine.
  • For npm packages, pushing to the registry is only possible with a token.

Prepare your npm Package

  • Ensure your npm package has a package.json file with all the required fields filled out, including "name", "version", and any dependencies.
  • The package name should follow the format @your-scope/package-name if you are using a scope.

Generating a Token for NPM Packages

To push packages to Gitea, you must have an access token with read and write permissions. Creating Access Tokens for Pushing Packages to Gitea documentation guides you on how to create such a token.


Guide

Configuration

In your terminal, configure npm to use your Gitea npm registry. Replace the placeholders {pkey} and {token} with actual values. Replace CUSTOMER with your customer ID.

npm config set registry https://gitea-CUSTOMER.devops.t-systems.net/api/packages/{pkey}/npm/
npm config set -- '//gitea-CUSTOMER.devops.t-systems.net/api/packages/{pkey}/npm/:_authToken' "{token}"

Parameter

Description

pkey

Project Key in DevOps Portal refers to Organisation in Gitea

token

Your access token.
Refer to Creating Access Tokens for Pushing Packages to Gitea for instructions

Error

A package always belongs to an organisation, not a repository. To link an (already uploaded) package to a repository, open the settings page on that package and choose a repository to link this package to. The entire package will be linked, not just a single version.

Publish a package

First, navigate to the directory where your NPM package is located on your local computer. For instance : C:\myuser\myfiles\mypackages\packagetopush. 
After navigating to the path, proceed by running the following command to push your package:

npm publish 
Error

If a package of the same name and version already exists, you'll need to delete the existing one before publishing the new version.

Once published, the package will be accessible within the "Packages" section of the organization in Gitea.
The following picture displays how a package appears in Gitea after being pushed to the package registry.
image-2024-2-9_10-26-37.png