You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

2 D铆as
19 Hrs
19 Min
10 Seg
Curso de Fundamentos de Node.js

Curso de Fundamentos de Node.js

Oscar Barajas Tavares

Oscar Barajas Tavares

Publicaci贸n de Paquetes con NPM

7/20
Resources

Publishing packages in NPM is a fundamental skill for any JavaScript developer who wants to share their creations with the community. This process not only allows you to distribute reusable code, but also contributes to the development ecosystem and puts your work on the open source map. Mastering this workflow will open both professional and collaborative doors in the world of web development.

How to publish your package on NPM?

Publishing a package on NPM requires following a series of structured steps to ensure that your code is ready to be shared with the developer community. The process starts with the preparation of your code and ends with the official publication in the NPM registry.

To begin with, it is essential to have our code reviewed and validated, making sure that it contains the minimum elements necessary to function correctly. In addition, we must add certain specific configurations for the publication process to be successful.

Why is it important to upload your code to GitHub?

The first recommended step is to upload your code to a repository on GitHub. This has multiple benefits:

  • It allows the entire community to view and review your code.
  • Facilitates collaboration and contributions
  • Serves as a reference point for documentation
  • Increases the credibility of your package

To connect your local code to a GitHub repository, follow these steps:

  1. Create a repository on GitHub
  2. Add the remote origin to your local project
  3. Check the status of your files with git status
  4. Add the files with git add .
  5. Commit with git commit -m "Initial commit".
  6. Upload the changes with git push origin main

Once this process is completed, your code will be available on GitHub with all the necessary information such as description, installation instructions and other relevant resources.

How to authenticate on NPM to publish?

To publish a package on NPM, you need to be authenticated on the service. The authentication process is simple:

npm adduser

This command will start the authentication process, opening a window in your browser where you must:

  1. Log in to your NPM account (if you don't have one, you will need to register).
  2. You can use your GitHub account to facilitate registration.
  3. Complete two-factor authentication if you have it enabled

Once authenticated, you can return to your terminal where you will see confirmation that you are successfully logged into your NPM account.

How to validate and publish your package?

Before publishing definitively, it is advisable to validate exactly what information will be sent. For this, you can use:

npm publish --dry-run

This command will show you detailed information about what will be included in your package:

  • Package name and version
  • Files to be included (README, package.json, code files)
  • Package size
  • Integrity information

This pre-validation allows you to detect potential problems, such as the inclusion of unwanted files (for example, if you have not properly ignored the node_modules folder).

Once you are satisfied with the information displayed, you can proceed to officially publish your package:

npm publish

The system will ask you to authenticate again (possibly with two-factor authentication), and then proceed to publish your package to the NPM registry.

How to verify that your package has been successfully published?

Once the publishing process is complete, you can verify that your package is available by visiting the NPM website. In your account, in the packages section, you will be able to find the package you just published.

Your package page will display:

  • The name and version
  • Installation instructions
  • The documentation you have included in the README
  • Other relevant metadata

To improve your package, consider:

  • Creating more detailed documentation
  • Adding the link to the GitHub repository in package.json
  • Release new versions with improvements and fixes

If you want to go deeper into using NPM, there are specific courses that cover in detail all aspects of package creation, publishing and maintenance.

Publishing a package in NPM is a significant achievement that demonstrates your skills as a developer and your willingness to contribute to the community. Have you already published your first package? Share your experience and the link to your build so that others can learn about your work and learn from your process.

Contributions 3

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Hola a todos. Comparto mi paquete en npm. (`https://www.npmjs.com/package/platzidate-javierxd1?activeTab=readme`) Consejo: Recuerden cambiar el nombre del paquete para que lo puedan publicar en NPM
Para los que esten utilizando WSL, y les de un error como este: ![](https://static.platzi.com/media/user_upload/upload-ca1b0d8a-e510-41a1-816c-713ec00031e9.png) utilizen este comando: npm login --auth-type=legacy les pedira su usuario, contrase帽a y un codigo que les llegara a ese correo, si lo hacen correctamente debe aparecer asi: ![](https://static.platzi.com/media/user_upload/upload-4ace5261-8c83-41ee-8739-1b6341dfe2ed.png)
Tuve este error al publicar mi paquete por que ya existia otro paquete con el mismo nombre ![](https://static.platzi.com/media/user_upload/upload-42e32000-1636-41d3-8042-d3f38b1634c0.png) as铆 que lo solcuione cambiando el nombre de mi paquete en el package.json ![](https://static.platzi.com/media/user_upload/upload-4b47743f-4542-494a-b095-808f1acc21f5.png)