NPM Guide (i)

Source: Internet
Author: User
Tags install node

Recently while there is time to translate NPM guide, using Markdown typesetting, the first translation of many are in accordance with their own understanding of the meaning, there may be a lot of words are not exact place, but still hope to see the people help it.

See the process for reference: NPM official documentation.

What's (What's NPM?)

NPM makes it easy for JavaScript developers to share and reuse code. And it's easy to share the code snippets you've written.

Install node. js and update NPM (installing node. js and updating NPM)
    1. Install node. js (Installing node. js)

If you are a user of OS X and Windows, the best way to install node. JS is to use the installation package installer, and the installation package is downloaded by the user under Node.js,linux. You can also use the node. JS binary resource Bundle, which is the source bundle for node. js, but it needs to be compiled manually. Check the Nodesource ' s binary distributions to see if there is an updated version that fits your system. After the installation is complete.

Note: It is best to use node-v to view the version of node. js, preferably on v0.10.32

    1. Update NPM (Updating NPM)

With the installation package installed in node, NPM is already integrated, but since NPM is updated faster than node version, you should make sure that the NPM installed is up-to-date. You can use npm-v to view the version information for NPM. The version of NPM is preferably above 2.1.8 .

    1. Manually installing NPM (installing NPM manually)

For users who are already more advanced. The NPM module can download https://registry.npmjs.org/npm/-/npm-{version}.tgz at this address.

Fix NPM License (fixing NPM permissions)

You may encounter eacces This error when you install a package globally. This indicates that you do not have permission to write to the file directory where NPM packages and instructions are stored. You can use the following two ways to fix this problem:

    1. Change the license for the NPM default directory.
    2. Make the default directory in NPM point to another directory.

You should return one before you move forward.

Change the license for the NPM default directory

1. Locate the path to the NPM default directory.

npm config get prefix

For most systems this should be:/usr/local

Note: If the actual path is:/usr, then use the second method.

2. Change the owner of the NPM default directory to the current user name (your user name!). )

sudo chown-r $ (whoami) $ (npm config get prefix)/{lib/node_modules,bin,share}

Through NPM or other tools. This will change the default permissions for subfolders (Lib/node_modules, Bin, and share).

Make the default directory in NPM point to another directory

In many cases, when you don't want to change the relationship between the default directory and NPM (changing these can be a mistake). For example, when you share your system with other people. Therefore, you can make NPM point to another directory, not the default directory. In this case, this directory will be hidden in our main file.

1. Create a file directory to hold the global installation package

mkdir ~/.npm-global

2. Configure NPM to use a new directory

NPM config set prefix ' ~/.npm-global '

3. Open or create a ~/.profile this file, and in this file the Zhongtian sword follows the instructions:

Export Path=~/.npm-global/bin: $PATH

4. Go back to the command line. Update your system parameters.

SOURCE ~/.profile

Test: To download a package globally without using sudo

NPM install-g Jshint

You can use an environment variable like the following to replace 2-4 steps (in case you don't want to modify ~/.profile ).

NPMCONFIGprefix=~/.npm-global npm install-g jshint

NPM Guide (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.