NodeJS and NPM installation and configuration steps (for windows) and environment variable details, nodejsnpm

Source: Internet
Author: User

NodeJS and NPM installation and configuration steps (for windows) and environment variable details, nodejsnpm

1, NodeJS installation under windows is more convenient (v0.6.0 version, support windows native), just need to log on to the official website (http://nodejs.org/), you can see the "INSTALL" button on the home page, click it to automatically download and install it.

2. The installation process is basically "NEXT. (When installing the msi file for windows, the system variable of path will be directly added. The variable value is your installation path, for example, "C: \ Program Files \ nodejs ").

3. After the installation is complete, run cmd (win + r and Enter cmd) to test whether the installation is successful. Method: Enter node-v in cmd. if the version prompt is displayed, the NodeJS installation is completed.


4. Install npm. The new NodeJS version has integrated npm, so npm has been installed together. You can also use the cmd command line to enter "npm-v" to test whether the installation is successful. If the version prompt is displayed, it will be OK.

5. The establishment of general NodeJS has been completed so far. If you cannot wait, you can enter "node" in "cmd" and enter "node development mode". Enter your NodeJS first sentence: "hello world"-input: console. log ('Hello World ').

6. npm is used as a node. js module for management. Previously, I had taken a big detour when installing the configuration module because I did not systematically read the information. Therefore, it is necessary to list the information.

① First, we need to configure the npm global module storage path and cache path. For example, I want to put the above two folders in the main directory of NodeJS, create the "node_global" and "node_cache" folders under NodeJs. For example


② Start cmd and enter

Npm config set prefix "C: \ Program Files \ nodejs \ node_global" and npm config set cache "C: \ Program Files \ nodejs \ node_cache"

3. Now let's try to install a module and select express, a commonly used module. Similarly, in the cmd command line, enter "npm install express-g" ("-g" indicates that the parameter is installed in the global directory, that is, the "C: \ Program Files \ nodejs \ node_global .). After the installation process in cmd is rolled over, the system will prompt "express" which is installed, the version, and its directory structure. For example


4. Close cmd and open the system dialog box. Right-click my computer and choose Properties> advanced system Settings> advanced> environment variables ". For example


⑤ Enter the environment variable dialog box, create "NODE_PATH" under the system variable, and enter "C: \ Program Files \ nodejs \ node_global \ node_modules". (Ps: This step is critical .)

2014.4.19 added: Because the default address of the module is changed, the above user variables must be changed (the user variable "PATH" is changed to "C: \ Program Files \ nodejs \ node_global \ "). If you do not use the module," xxx is not an internal or external command, this error is not a runable program or batch file.

6. If the above steps are OK, we can start the cmd command line again, enter node, and enter "require ('express ') to test whether the Global Path of the node module is correctly configured. If it is correct, cmd will list the relevant information of express. For example, if an error occurs, the Node path configuration is incorrect. You can check step 4 and Step 5)


7. Conclusion.

The above is my operation when installing and configuring NodeJS. For the sake of the newbie, I used google to read a lot of information and hope it will be helpful to my friends who are new to NodeJS.

PS: The ide I am using is a combination of Sublime text 2 + NodeJS plug-ins. It is very convenient to compile node programs directly in Sublime.

Related Article

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.