Publishing a npm package

The most popular way of making a package available to developers is publishing it to npm, the package manager for Node.js.

We used it in all the examples in this book and you have seen how easy it is to install a package: It is just a matter of running npm install package, and that is it. What you may not know is how easy it is to publish a package as well.

First of all, if you move into an empty directory and write in your terminal:

npm init

A new package.json is created and some questions will be displayed. The first one is the package name, which defaults to the folder name, and then the version number. These are the most important ones because the first is the name that the users of your package will refer to when they ...

Get React Design Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.