NodeJS, NPM installation configuration and test steps (Windows version)

Source: Internet
Author: User
Tags sublime text

1, Windows Nodejs installation is more convenient (after v0.6.0 version, support Windows native), only need to login official website (http://nodejs.org/), you can see the homepage of the "Install" button, A direct click will automatically download the installation.

2, the installation process is basically directly "NEXT" can be. (The installation MSI file for Windows adds the system variable for path directly in the process, and the variable value is your installation path, such as "C:\Program Files\nodejs"). 3. After the installation is complete, you can use CMD (win+r and then enter CMD to enter) to test whether the installation is successful. Method: Input in cmdNode-v, the version prompt appears to complete the Nodejs installation. 4, the installation of NPM. Since NPM has been integrated with the new version of Nodejs, NPM has been installed as well. You can also use the cmd command line to enter "npm-v "To test whether the installation was successful. For example, the version prompt will be OK.  5, the construction of conventional nodejs has been completed so far, you can enter "cmd" input "node" into node development mode, enter your Nodejs first sentence: "Hello World"-Input: Console.log (' Hello World '). In addition, you can write a JS file to test the HTTP request, the code is as follows:
var http = require ("http"); Http.createserver (function(request, Response) {      Response.writehead (200, { "Content-type": "Text/plain"});      Response.Write ("Hello World 9999"); Response.End ();}). Listen (9999); Console.log ("Nodejs Start listen 9999 port!");     

Save the above code as a test.js file, then switch to the current file directory on the command line, execute node test.js, then open IE, enter http://127.0.0.1:9999 to see the strings we are familiar with.

6, NPM as a Nodejs module management, before I because no system to see the data so that the installation of the configuration module took a large part of the detour, so now it is necessary to list to record. ①, we will first configure the NPM Global Module storage path and the path of the cache, for example, I would like to put the above two folder in the Nodejs home directory, the Nodejs under the establishment of "Node_global" and "Node_cache" two folders. such as ②, start cmd, enter

NPM config set prefix "C:\Program files\nodejs\node_global"
And
NPM config set cache "C:\Program files\nodejs\node_cache"

③, now let's install a module to try, choose Express this more common module. Also in the cmd command line, enter "NPM Install Express-g" ("-g" This parameter means to be loaded into the global directory, which is said to set the "C:\Program Files\nodejs\node_global" inside. )。 After the installation process in the CMD is finished scrolling, it will prompt "express" where it is installed, the version and its directory structure. Such as ④, close cmd, open the System dialog box, my Computer right-click Properties-Advanced system Settings-advanced-environment variables. such as ⑤, enter the Environment Variables dialog box, under System variables, create a new "Node_path ", enter"C:\Program files\nodejs\node_global\node_modules ". (PS: This step is quite critical.) ) 2014.4.19 added: Because the module's default address is changed, the above user variables are changed (the user variable "PATH" is modified to "C:\Program files\nodejs\node_global\"), Not using the module causes the input command to appear "XXX is not an internal or external command, it is not a running program or batch file" error.

⑥, the above steps are OK, we can open the cmd command line again, enter node, enter "require (' Express ')" To test the next node's module global path is configured correctly. The correct CMD will list information about the Express. such as (if the error is generally node_path configuration is wrong, you can check the next step ④⑤)

In addition, we also create a JS file to test we just installed the Express component, the code is as follows:
var express = require (' Express 'var app =function(req, res) {res.send ("Hello World 8888"); Console.log ("Hello World 8888"); App.listen (' 8888 '); Console.log ("Nodejs Start listen 8888 port!");     

Save the above code as a testexpress.js file, then on the command line switch to the current save file directory, execute node testexpress.js, and then open IE Browser, enter http://127.0.0.1:8888 to see the familiar string.

7, concluding remarks. The above is my installation configuration Nodejs when the operation, because of the novice's sake, with the help of Google access to a lot of information, I hope that the first contact with Nodejs friends are a bit helpful. PS: The IDE I'm using now isSublime Text 2 + Nodejs plug-in this combination, can be in the Sublime directly compiled node program, very convenient. Source: http://xiaoyaojones.blog.163.com/blog/static/28370125201351501113581/

NodeJS, NPM installation configuration and test steps (Windows version)

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.