While npm and bower use incompatible organizational patterns, both may
be used in a single project since they use different metadata files
bower.json), and they install packages into
different subdirectories. It's not uncommon to use npm to manage
server-side packages and bower to manage client-side packages.
Getting started with package managers is straightforward. The following examples are for bower and npm, but similar concepts exist for the others.
After installing bower or npm, type
bower init or
npm init at the root
directory of your project. The package manager will ask several questions.
Your answers will be used to create a
metadata file for your project.
To search for available packages to install, type
bower search <keywords>
npm search <keywords>. A list of matching packages will be displayed.
To install a package into the local module cache and then copy its latest
version into your project, type
bower install <package-name> or
npm install <package-name>. To install a specific version, the syntax
varies slightly amongst package managers:
bower install <package-name>#<package-version>
npm install <package-name>@<package-version>.
You may also save each package's version info into your project's metadata file. The package manager -- as well as other third-party tools -- can use the metadata to simplify client-side maintenance, build, testing, and bootstrapping tasks.
The best way to save a package's version info into your project's metadata
file, is to use the
--save option while installing the package. Type
bower install --save <package-name>#<package-version>
npm install --save <package-name>@<package-version>.