Chapter 1. The Setup

 

1.  The Node Package Manager (NPM) allows you to easily manage modules in projects by downloading packages, resolving dependencies, running tests, and installing command-line utilities.

 

2.  NPM is a program written in Node.JS and shipped with the binary packages.

 

3.  If you compiled node from the source files, you want to install NPM as follows:

  $ curl http://npmjs.org/install.sh | sh

 

4.  The package.json file is the file that describes your project to both Node.JS and NPM. The only required fields are name and version. Normally, modules have dependencies, which is an object that references other projects by the name and version they defined in their package.json files.

 

5.  To tell Node which file to look for when someone calls require(‘my-project’) we can specify the main property in the package.json.

 

6.  To learn about all the possible properties for the package.json file, run:

  $ npm help json

  If you want to learn more about a certain NPM command, type npm help <command>.

 

7.  If you never intend to publish a certain project, add “private”: “true” to your package.json. This prevents accidental publication.

 

8.  Some projects distribute command-line tools that were written in Node. When that’s the case, you need to install them with the -g flag. If you want to distribute a script like this, include a flag “bin”: “./path/to/script” pointing to your executable script or binary when publishing.

 

9.  If you want to search for plugins related to realtime, for example, you would execute the following:

  $ npm search realtime

  This will search all the published modules that contain realtime in their name, tags, and description fields.

 

10.  Once you find a package that interests you, you can see its package.json and other properties related to the NPM registry by running npm view followed by the module name.

 

11.  npm install --save moduleA will automatically add moduleA as dependency to your package.json file.

 

12.Run npm update under your project folder, you will get your dependencies updated.

 

13.To change the location of global node module folder , add a line:

  prefix=PATH_OF_GLOBAL_MODULE 

  to ~/.npmrc file.

 

你可能感兴趣的:(nodejs,npm,package.json,npm install,npm link)