Consuming Node.js modules
In this recipe, we are going to learn how to consume npm
modules from the public npm
registry using the npm
CLI.
Important note
Yarn is a popular alternative package manager for JavaScript and was created as an alternative to the npm
CLI in 2016. When Yarn was released, npm
did not have the package-lock.json
feature to guarantee consistency of which specific versions of modules would be installed. This was one of the key features of Yarn. At the time of writing, the Yarn CLI offers a similar user experience to what the npm
CLI provides. Yarn maintains a registry that is a reverse proxy to the npm registry. For more information about Yarn, check out their Getting Started Guides: https://yarnpkg.com/getting-started.
Getting ready
To get started, we first need to create a new directory to work in:
$ mkdir consuming-modules $ cd consuming-modules
We will also need a file where we can attempt to execute the imported module:
$ touch require...