Skip to main content
Frecuentemente publicamos actualizaciones de nuestra documentación. Es posible que la traducción de esta página esté en curso. Para conocer la información más actual, visita la documentación en inglés. Si existe un problema con las traducciones en esta página, por favor infórmanos.

Esta versión de GitHub Enterprise se discontinuó el 2022-06-03. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.

Working with the npm registry

You can configure npm to publish packages to Registro del paquete de GitHub and to use packages stored on Registro del paquete de GitHub as dependencies in an npm project.

El Registro del paquete de GitHub se encuentra disponible con GitHub Free, GitHub Pro, GitHub Free para organizaciones, GitHub Team, Nube de GitHub Enterprise, GitHub Enterprise Server 3.0 o superior y GitHub AE. Para obtener más información sobre cómo mejorar tu instancia de GitHub Enterprise Server, consulta la sección "Acerca de las mejoras a los lanzamientos nuevos" y refiérete al Asistente de mejora para encontrar la ruta de mejora desde tu versión de lanzamiento actual.

Nota: Este tipo de paquete podría no estar disponible para tu instancia, ya que los administradores de sitio pueden habilitar o inhabilitar cada tipo de paquete compatible. Para obtener más información, consulta la sección "Configurar el soporte de los paquetes para tu empresa".

Limits for published npm versions

If you publish over 1,000 npm package versions to Registro del paquete de GitHub, you may see performance issues and timeouts occur during usage.

In the future, to improve performance of the service, you won't be able to publish more than 1,000 versions of a package on GitHub. Any versions published before hitting this limit will still be readable.

If you reach this limit, consider deleting package versions or contact Support for help. When this limit is enforced, our documentation will be updated with a way to work around this limit. For more information, see "Contacting Support."

Authenticating to Registro del paquete de GitHub

You need an access token to publish, install, and delete packages.

You can use a personal access token (PAT) to authenticate to Registro del paquete de GitHub or the GitHub Enterprise Server API. When you create a personal access token, you can assign the token different scopes depending on your needs. For more information about packages-related scopes for a PAT, see "About permissions for GitHub Packages."

To authenticate to a Registro del paquete de GitHub registry within a GitHub Actions workflow, you can use:

  • GITHUB_TOKEN to publish packages associated with the workflow repository.
  • a PAT to install packages associated with other private repositories (which GITHUB_TOKEN can't access).

Para obtener más información sobre el GITHUB_TOKEN que se utiliza en los flujos de trabajo de GitHub Actions, consulta la sección "Autenticarse en un flujo de trabajo".

Authenticating with a personal access token

Debes utilizar un token de acceso personal con los alcances adecuados para publicar e instalar paquetes en Registro del paquete de GitHub. Para obtener más información, consulta "Acerca de Registro del paquete de GitHub".

You can authenticate to Registro del paquete de GitHub with npm by either editing your per-user ~/.npmrc file to include your personal access token or by logging in to npm on the command line using your username and personal access token.

To authenticate by adding your personal access token to your ~/.npmrc file, edit the ~/.npmrc file for your project to include the following line, replacing HOSTNAME with the host name of tu instancia de GitHub Enterprise Server and TOKEN with your personal access token. Create a new ~/.npmrc file if one doesn't exist.

If your instance has subdomain isolation enabled:

//npm.HOSTNAME//:_authToken=TOKEN

If your instance has subdomain isolation disabled:

//HOSTNAME/_registry/npm/:_authToken=TOKEN

To authenticate by logging in to npm, use the npm login command, replacing USERNAME with your GitHub username, TOKEN with your personal access token, and PUBLIC-EMAIL-ADDRESS with your email address.

If Registro del paquete de GitHub is not your default package registry for using npm and you want to use the npm audit command, we recommend you use the --scope flag with the owner of the package when you authenticate to Registro del paquete de GitHub.

If your instance has subdomain isolation enabled:

$ npm login --scope=@OWNER --registry=https://npm.HOSTNAME/

> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS

If your instance has subdomain isolation disabled:

$ npm login --scope=@OWNER --registry=https://HOSTNAME/_registry/npm/
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS

Publishing a package

Note: Package names and scopes must only use lowercase letters.

By default, Registro del paquete de GitHub publishes a package in the GitHub repository you specify in the name field of the package.json file. For example, you would publish a package named @my-org/test to the my-org/test GitHub repository. You can add a summary for the package listing page by including a README.md file in your package directory. For more information, see "Working with package.json" and "How to create Node.js Modules" in the npm documentation.

You can publish multiple packages to the same GitHub repository by including a URL field in the package.json file. For more information, see "Publishing multiple packages to the same repository."

You can set up the scope mapping for your project using either a local .npmrc file in the project or using the publishConfig option in the package.json. Registro del paquete de GitHub only supports scoped npm packages. Scoped packages have names with the format of @owner/name. Scoped packages always begin with an @ symbol. You may need to update the name in your package.json to use the scoped name. For example, "name": "@codertocat/hello-world-npm".

Después de que publiques un paquete, puedes verlo en GitHub. Para obtener más información, consulta "Visualizar paquetes".

Publishing a package using a local .npmrc file

You can use an .npmrc file to configure the scope mapping for your project. In the .npmrc file, use the Registro del paquete de GitHub URL and account owner so Registro del paquete de GitHub knows where to route package requests. Using an .npmrc file prevents other developers from accidentally publishing the package to npmjs.org instead of Registro del paquete de GitHub.

  1. Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."

  2. En el mismo directorio que tu archivo package.json, crea o edita un archivo .npmrc para incluir una línea que especifique la URL de Registro del paquete de GitHub y el propietario de la cuenta. Reemplaza OWNER con el nombre de la cuenta de usuario u organización a la que pertenezca el repositorio que contiene tu proyecto.

    Si se habilita el aislamiento de subdominios:

    @OWNER:registry=https://npm.HOSTNAME

    Si se inhabilita el aislamiento de subdominios:

    @OWNER:registry=https://HOSTNAME/_registry/npm
  3. Agrega el archivo .npmrc al repositorio en donde Registro del paquete de GitHub pueda encontrar tu proyecto. Para obtener más información, consulta la sección "Agregar un archivo a un repositorio."

  4. Verify the name of your package in your project's package.json. The name field must contain the scope and the name of the package. For example, if your package is called "test", and you are publishing to the "My-org" GitHub organization, the name field in your package.json should be @my-org/test.

  5. Verifica el campo repository en el package.json. de tu proyecto. El campo repository debe coincidir con la URL de tu repositorio de GitHub. Por ejemplo, si la URL de tu repositorio es github.com/my-org/test, entonces el campo de repositorio debe ser git://github.com/my-org/test.git.

  6. Publicar el paquete:

    $ npm publish

Publishing a package using publishConfig in the package.json file

You can use publishConfig element in the package.json file to specify the registry where you want the package published. For more information, see "publishConfig" in the npm documentation.

  1. Edit the package.json file for your package and include a publishConfig entry.

    If your instance has subdomain isolation enabled:

    "publishConfig": {
      "registry":"https://npm.HOSTNAME/"
    },

    If your instance has subdomain isolation disabled:

    "publishConfig": {
       "registry":"https://HOSTNAME/_registry/npm/"
     },
  2. Verifica el campo repository en el package.json. de tu proyecto. El campo repository debe coincidir con la URL de tu repositorio de GitHub. Por ejemplo, si la URL de tu repositorio es github.com/my-org/test, entonces el campo de repositorio debe ser git://github.com/my-org/test.git.

  3. Publicar el paquete:

    $ npm publish

Publishing multiple packages to the same repository

To publish multiple packages to the same repository, you can include the URL of the GitHub repository in the repository field of the package.json file for each package.

To ensure the repository's URL is correct, replace REPOSITORY with the name of the repository containing the package you want to publish, and OWNER with the name of the user or organization account on GitHub that owns the repository.

Registro del paquete de GitHub will match the repository based on the URL, instead of based on the package name.

"repository":"https://HOSTNAME/OWNER/REPOSITORY",

Installing a package

You can install packages from Registro del paquete de GitHub by adding the packages as dependencies in the package.json file for your project. For more information on using a package.json in your project, see "Working with package.json" in the npm documentation.

By default, you can add packages from one organization. For more information, see "Installing packages from other organizations."

You also need to add the .npmrc file to your project so that all requests to install packages will go through Registro del paquete de GitHub. When you route all package requests through Registro del paquete de GitHub, you can use both scoped and unscoped packages from npmjs.org. For more information, see "npm-scope" in the npm documentation.

  1. Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."

  2. En el mismo directorio que tu archivo package.json, crea o edita un archivo .npmrc para incluir una línea que especifique la URL de Registro del paquete de GitHub y el propietario de la cuenta. Reemplaza OWNER con el nombre de la cuenta de usuario u organización a la que pertenezca el repositorio que contiene tu proyecto.

    Si se habilita el aislamiento de subdominios:

    @OWNER:registry=https://npm.HOSTNAME

    Si se inhabilita el aislamiento de subdominios:

    @OWNER:registry=https://HOSTNAME/_registry/npm
  3. Agrega el archivo .npmrc al repositorio en donde Registro del paquete de GitHub pueda encontrar tu proyecto. Para obtener más información, consulta la sección "Agregar un archivo a un repositorio."

  4. Configure package.json in your project to use the package you are installing. To add your package dependencies to the package.json file for Registro del paquete de GitHub, specify the full-scoped package name, such as @my-org/server. For packages from npmjs.com, specify the full name, such as @babel/core or @lodash. For example, this following package.json uses the @octo-org/octo-app package as a dependency.

    {
      "name": "@my-org/server",
      "version": "1.0.0",
      "description": "Server app that uses the @octo-org/octo-app package",
      "main": "index.js",
      "author": "",
      "license": "MIT",
      "dependencies": {
        "@octo-org/octo-app": "1.0.0"
      }
    }
    
  5. Install the package.

    $ npm install

Installing packages from other organizations

By default, you can only use Registro del paquete de GitHub packages from one organization. If you'd like to route package requests to multiple organizations and users, you can add additional lines to your .npmrc file, replacing HOSTNAME with the host name of tu instancia de GitHub Enterprise Server and OWNER with the name of the user or organization account that owns the repository containing your project.

If your instance has subdomain isolation enabled:

@OWNER:registry=https://npm.HOSTNAME
@OWNER:registry=https://npm.HOSTNAME

If your instance has subdomain isolation disabled:

@OWNER:registry=https://HOSTNAME/_registry/npm
@OWNER:registry=https://HOSTNAME/_registry/npm

Using the official NPM registry

Registro del paquete de GitHub allows you to access the official NPM registry at registry.npmjs.com, if your GitHub Enterprise Server administrator has enabled this feature. For more information, see Connecting to the official NPM registry.