node. JS Getting Started: Installation and configuration of NODE.JS&NPM

Source: Internet
Author: User
Tags git client install node visual studio 2010

node. JS Installation and Configuration

node. JS has been in existence for more than two years, and since it's been in rapid development, some of the previous installation configurations have been introduced for most of the 0.4.x versions, and not for the latest 0.6.x versions, we'll cover the installation and configuration of node. JS on the 0.6.x version. (This article takes 0.6.1 as an example, the remaining version of 0.6, just replace the version number.) From可以查看到最新的二进制版本和源代码).
    • node. JS installation under Windows platform
In the past, node. JS had not supported native compilation under the Windows platform and needed to emulate the POSIX system with Cygwin or MinGW to compile the installation. Fortunately, in June 2011, Microsoft started working with Joyent to migrate node. js to the Windows platform (Http://, The results of this collaboration were finally presented in the stable release of 0.6.x. This release makes node. js significantly more efficient on Windows platforms, easier and lighter to use, completely free from lab-like environments such as Cygwin or mingw, and shows higher performance than Linux in some details, see HTTP// Under the Windows (WINDOWS7) platform, I'll cover two ways to install node. js, the common and artistic installation method.
    • Common installation Methods
The common installation method is actually the simplest method, for most Windows users, are not too fond of tossing people, you can from here (    Download directly to the node. JS compiled MSI file.    Then double-click to complete the installation under the program's boot. Run directly on the command line: The NODE-V command lines will print out: v0.6.1 The boot step installs the Node.exe file into the C:\Program files (x86) \nodejs\ directory and adds the directory to the PATH environment variable.
    • The installation method of literature and art
The artistic installation method under the Windows platform is mainly offered to those students who love tossing and compiling. Before compiling the source code, you need to be aware of whether your Windows system contains compiled source tools. The source code for node. JS is primarily composed of C + + code and JavaScript code, but it uses the Gyp tool ( for project management of the source code, which is written in the Python language. On the Windows platform, node. JS uses Gyp to generate the visual Studio solution file, which is eventually compiled into a binary file by VC + + compilers. So, you need to meet the following two conditions: 1.    Python (node. JS recommends using 2.6 or later, not 3.0) and can be obtained from here ( 2. VC + + compiler, included in Visual Studio 2010 (VC + + Express also), VS2010 can be from here (    hh388567) found. Download node. js 0.6.1 version of the source Tarball ( and unzip it. Through the command line into the extracted source directory, execute the vcbuild.bat release command, and then after a long wait, after the completion of the compilation, in the release directory can be found in the compiled Node.exe file.    Execute node-v from the command line. The command line returns the result as: v0.6.1 in fact, if you have a WiX toolset ( in your compilation environment, execute the Vcbuild.bat MSI release command,    You will find Node.msi in the relase directory. Yes, we went back to the normal installation method at the beginning. The so-called literature and art is to take some more road, more to see some scenery.
    • node. JS installation under the Unix/linux platform
Because node. JS is still in the v0.x.x version of the rapid development, the Unix/linux platform's release will not be pre-set node binary files, compiled through the source code is the best choice for the present. And the students with Unix/linux system are mostly literary programmers, this section only describes how to compile and install through the source code.
    • Installation conditions
Like under the Windows platform, node. JS still manages the build project with the Gyp tool, unlike the final compilation with the Make tool. So under the Unix/linux platform you need the following prerequisites to ensure that the compilation is complete: 1. Python.    For Gyp, you can see if Python is installed by executing the python command under the shell, and confirm that the version meets the requirements (2.6 or later, but not 3.0). 2. Source code compilers, usually the Unix/linux platform comes with a C + + compiler (gcc/g++).        If not, install make,g++ These compilation tools through the current release of the package installation tool. A. The tool under Debian/ubuntu is Apt-get B. Redhat/centos under the Yum command c. MAC OS x You may need to install Xcode to get compiler-related vendor content Scala, which lets the Java platform programmed to reproduce 3. Second, if you plan to enable network encryption in node. JS, the cryptographic libraries of OpenSSL are also required. The cryptographic library is Libssl-dev and can be installed by commands such as Apt-get install Libssl-dev.
    • Check the environment and install
After completing the above prerequisites, we obtain the source code and conduct environmental inspection:
wget 6.1/node-v0.6.1.tar.gz  tar zxvf node-v0.6.1.tar.gz cd node-v0.6.1  ./configure  The above command is to download the latest version of the code through the wget command and unzip it: the/configure command will check whether the environment conforms to the NODEJS compilation needs. Checking for program g++ or C + +:/usr/bin/g++  Checking for program CPP:/usr/bin/cpp  Checking for program AR :/usr/bin/ar  Checking for program Ranlib:/usr/bin/ranlib  Checking for g++: ok  Checking for program GCC or cc:/usr/bin/gcc  Checking for program ar:/usr/bin/ar  Checking for program ranlib:/usr/bin/ranlib C Hecking for gcc:ok  Checking for library dl:yes  Checking for openssl:yes  Checking for library util : yes  Checking for library rt:yes  Checking for Fdatasync (2) with C + +: yes  ' Configure ' finished succes Sfully (7.350s)
If the check does not pass, make sure that the three conditions mentioned above are met. If the Configure command executes successfully, it can be compiled:
Make make Install
The Nodejs is compiled and installed with the Make tool (use sudo to ensure that you have permissions if making install is unsuccessful). After completing these two steps, check if the installation is successful: Node-v check to see if it is returned: v0.6.1 to this point, Nodejs has been compiled and installed. If you want to uninstall, you can perform the make uninstall to uninstall.

Installing NPM

The full name of NPM is node package Manager, and if you're familiar with Ruby's Gem,python pypl, setuptools,php pear, then you know what NPM is all about. Yes, it's Nodejs's package manager. The Nodejs itself provides the basic modules. However, the development of practical applications on these basic modules requires more work. Fortunately, when I wrote this article, NPM already has 5,112 Nodejs libraries or frameworks that can help nodejs developers with more complex applications in every way. The number and activity of these libraries also reflect the rapid and active development of the Nodejs community. I'll show you how to install NPM and a third-party library that installs Nodejs via NPM, and how to make better use of NPM in a mainland-based network environment.
    • Installing NPM under Unix/linux
As the NPM official website ( describes, installing NPM is just one line of command:
Curl Http:// | Sh
Here's the meaning of this command, Curl is to get this installation shell script through the Curl command, press post via pipe break | The obtained script is assigned to the SH command to execute. If the installation is unsuccessful without permissions, you need to add sudo to ensure the permissions:
Curl Http:// | sudo sh
After successful installation, the NPM command will be followed by a hint:
USAGE:NPM <command> where <command> is one of:adduser, Apihelp, author, bin, Bugs, C, cache, completion, con Fig, deprecate, Docs, edit, explore, FAQ, find, GET, help, Help-search, home, I, info, init, install, LA, link, list, LL, ln, LS, outdated, owner, pack, prefix, prune, publish, R, RB, rebuild, remove, restart, RM, Root, Run-script, S, SE, searc H, set, show, Star, start, stop, submodule, tag, test, UN, uninstall, unlink, Unpublish, Unstar, up, update, version, view , WhoAmI
We use underscore as an example to demonstrate the process of installing a third-party package via NPM.
NPM Install underscore
[email protected]./node_modules/underscore
Due to some special network environment, when installing third-party libraries directly through the NPM Install command, the state of the card will often appear. Fortunately, the domestic Cnode community @fire9 students to use their spare time to build a mirrored NPM library, the server is set up in Japan, you can bypass some unnecessary network problems. You can install a third-party library by following this command:
NPM--registry "" Install underscore
If you want to set it as the default repository, run the following command:
NPM Config Set registry ""
After Setup, you can not take the-registry parameter on each installation. It is worth mentioning that there is another mirror available, the mirror address is, if you want to use, replace the address of the above two lines of command.
    • Installing NPM under Windows
Because of the historical reasons for Nodejs's initial Linux development, NPM did not initially support the Windows environment, but as Nodejs successfully ported to the Windows platform, NPM's requirements for windows were growing. Let's start the NPM tour under Windows.
    • Install Git
Since the GitHub website does not support direct download of all submodule packages, it is necessary to check out all the source code through the Git tool. From Http://, you can download to msysgit the GIT client tool under this Windows platform. After the download, double-click Install.
    • Configure Git
Locate the bin location in the git installation path, such as: C:\Program files\git\bin \ To find the location of Git-core in the GIT installation path, such as C:\Program files\git\libexec\git-core\; C:\Program files\git\ "is the installation path and may not be the same as your installation path, replace the" C:\Program files\git\ "with your own path. Right-click Computer, properties, advanced system settings, environment variables, locate path in the system variables below, select Path, and choose Edit-- Copy the found bin and git-core paths to them, save and exit, "path", and enter the semicolon in the English state between each path ";" As an interval.
    • Download NPM Source code
Open the command-line tool (CMD) and execute the following command to check out all of NPM's source and dependency code and install NPM with Msysgit.
git clone--recursive git:// CD NPM node cli.js install NPM-GF
Before executing this code, make sure that the Node.exe is installed in the way that is node.msi, or in the PATH environment variable. This command also adds NPM to the PATH environment variable and can then execute the NPM command anywhere. If you encounter permissions errors in your installation, make sure that the CMD command-line tool is running as an administrator. After the installation is successful, execute the following command:
NPM Install underscore
[email protected]./node_modules/underscore
This is done with NPM installed under the Windows platform. If you encounter network problems that cannot be installed, refer to the NPM command under Linux to add a mirrored address.
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: 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.