Lesson 1: Getting started with Node.js CHAPTER 8 351
You see npm sending HTTP GET and PUT methods until the publishing is complete. If you
have no errors, the package should be published and immediately available for everyone
to use.
Installing and using the package
Now that your package is published, you can install it and use it. You can install the package
globally, or you can install it locally to the application you’re creating. Installing the pack-
age globally gives all applications the same version of the package so that when you update
the global package with a new version, all applications get the new version. If you install the
package locally to the application, you reinstall the package for each application. You can
update the package for one application, and you don’t need to worry about updating the
package for all applications. The global option is typically more appealing to most people,
but often you don’t want to be forced into regression testing for all applications when you
update the package. This choice is about having control to update when needed versus the
convenience of updating all at once.
In this example, a new application, math_user, is created, so this folder is created under the
node_samples folder.
To install the package locally, use the command prompt window to navigate to the folder
that contains your application and enter the following command.
npm install math_example
This creates a node_modules subdirectory; in the folder that contains your application is a
folder for the installed package with all its files.
To install the package globally, type the following command.
npm install -g math_example
Figure 8-4 shows the screen after executing this command. The last line shows the folder
location in which the package was installed.
FIGURE 8-4 he successful global package installT