node. JS installation and configuration--ingest

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 http://nodejs.org/#download可以查看到最新的二进制版本和源代码).

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://www.infoq.com/cn/news/2011/06/node-exe), 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// Www.infoq.com/news/2011/11/Nodejs-Windows.

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 (http://nodejs.org/dist/v0.6.1/node-v0.6.1.msi Download directly to the node. JS compiled MSI file. Then double-click to complete the installation under the program's boot.

Run directly from the command line:

The command lines will print out:

This 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 (http://code.google.com/p/gyp/) 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 (http://python.org/).
    2. VC + + compiler, included in Visual Studio 2010 (VC + + Express also), VS2010 can be found here (http://msdn.microsoft.com/en-us/vstudio/hh388567).

Download node. js 0.6.1 version of the source Tarball (http://nodejs.org/dist/v0.6.1/node-v0.6.1.tar.gz) 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:

In fact, if you have a WiX toolset (http://wix.sourceforge.net/) in your build environment and you 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. The source code compiler, 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.
      1. The tool under the Debian/ubuntu is Apt-get
      2. Redhat/centos through the Yum command
      3. Under Mac OS x you may need to install Xcode to get the compiler

    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 http://nodejs.org/dist/v0.6.1/node-v0.6.1.tar.gz  tar zxvf node-v0.6.1.tar.gz  cd node-v0.6.1  . Configure  above a few lines of 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 Nodejs's 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/b In/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  Checking for Gcc:ok  Checking for library Dl:yes
   checking for Openssl:yes  Checking for library Util:yes  Checking for library rt:yes  Checking for FD Atasync (2) with C + +: Yes  

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  

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 to see if the installation was successful:

Check to see if it returns:

At this point, the Nodejs has been compiled and the installation is complete. If you want to uninstall, you can perform the make uninstall to uninstall.

Summary

The above describes the installation of *nix and the Windows platform under Nodejs, and can then write example.js files as described on the NODEJS official website.

var http = require (' http ');  Http.createserver (function (req, res) {      Res.writehead ($, {' Content-type ': ' Text/plain '});      Res.end (' Hello world\n ');  }). Listen (1337, "127.0.0.1");  

Execute it on the command line:

You will be able to access http://127.0.0.1:1337 via the browser to get Hello World response.

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 (http://npmjs.org/) describes, installing NPM is just one line of command:

Here's the meaning of this command, Curl http://npmjs.org/install.sh 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:

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, complet Ion,  Config, deprecate, docs, edit, explore, FAQs, 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,< C6/>run-script, S, SE, Search, set, show, Star, start, stop,  submodule, tag, test, UN, uninstall, unlink, Unpublish,  

We use underscore as an example to demonstrate the process of installing a third-party package via NPM.

Return:

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:

If you want to set it as the default repository, run the following command:

NPM Config Set registry "http://npm.hacknodejs.com/"

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 http://registry.npmjs.vitecho.com, 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.

Installing the Git tool

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://code.google.com/p/msysgit/downloads/list, You can download to msysgit the GIT client tool under this Windows platform (the latest version of the file is Git-1.7.7.1-preview20111027.exe). After the download, double-click Install.

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. (switch directories)

git clone--recursive git://github.com/isaacs/npm.git  CD NPM  

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:

Return:

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.

Reprint http://lklkdawei.blog.163.com/blog/static/32574109201242511151666/

node. JS installation and configuration--ingest

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.