Node. js getting started Tutorial: install and configure Node. js text tutorial on windows and Linux, and install and configure node. js

Source: Internet
Author: User
Tags install node

Node. js getting started Tutorial: install and configure Node. js text tutorial on windows and Linux, and install and configure node. js

This section describes how to install Node. js on Windows and Linux.

This tutorial uses Node. js v0.10.26 as an example.

The Node. js installation package and source code are: http://www.nodejs.org/download /.

Select the Node. js installation package you need based on different platform systems.

Note:To install Node. js on Linux, Python 2.6 or 2.7 is required. We do not recommend that you install Python 3.0 or later.

Install Node. js on ipvwv

Windows Installation Package (. msi):

32-bit installation package: http://nodejs.org/dist/v0.10.26/node-v0.10.26-x86.msi

64-bit installation package: http://nodejs.org/dist/v0.10.26/x64/node-v0.10.26-x64.msi

Installation steps:

Step 1: double-click the downloaded installation package node-v0.10.26-x86.msi, as shown below:

Step 2: Click Run. The following page is displayed:

Step 3: select the accept protocol option and click next:

Step 4: The default installation directory of Node. js is "C: \ Program Files \ nodejs \". You can modify the Directory and click next (next ):

Step 5: Click the tree icon to select the desired installation mode, and then click next (next)

Step 6: Click Install to Install Node. js. You can also click Back to modify the previous configuration. Then click next ):

Installation Process:

Click Finish to exit the installation wizard.

Check whether Node. js is configured for the PATH environment variable. Click Start = run = and enter "cmd" => enter the command "path". The following result is output:

Copy codeThe Code is as follows: PATH = C: \ oraclexe \ app \ oracle \ product \ 10.2.0 \ server \ bin; C: \ Windows \ system32; C: \ Windows; C: \ Windows \ System32 \ Wbem; C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 \; c: \ python32 \ python; C: \ MinGW \ bin; C: \ Program Files \ GTK2-Runtime \ lib; C: \ Program Files \ MySQL Server 5.5 \ bin; C: \ Program Files \ nodejs \; C: \ Users \ rg \ AppData \ Roaming \ npm

We can see that the environment variable contains C: \ Program Files \ nodejs \

Check the Node. js version

Install Windows binary file (.exe):

32-bit installation package: http://nodejs.org/dist/v0.10.26/node.exe

64-bit installation package: http://nodejs.org/dist/v0.10.26/x64/node.exe

Installation Steps

Step 1: double-click the downloaded installation package Node.exe. The following page is displayed:

Click Run to display the command line window:

Version Test

Enter the directory where node.exe is located, as shown below:

If you obtain the preceding output, you have successfully installed Node. js.

Install Node. js Ubuntu on Linux

The following section describes how to install Node. js in Ubuntu Linux. For other Linux systems, such as Centos, follow these steps.

Get the Node. js source code on Github:

After the download is complete, change the source package name to 'node '.

Modify directory permissions:

Use './configure' to create a compilation file.

Compile: make.

Complete the installation: make install.

Finally, run the 'node -- version' command to check whether node. js is successfully installed.

Install nodejs in centOS

1. Download the source code. download the latest nodejsrepository at http://nodejs.org/. this document uses v0.10.24as an example:

Copy codeThe Code is as follows: cd/usr/local/src/wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz

2. decompress the source code

Copy codeThe Code is as follows: tar zxvf node-v0.10.24.tar.gz

3. Compile and install

Copy codeThe Code is as follows: cd node-v0.10.24./configure -- prefix =/usr/local/node/0.10.24makemake install

4. Configure NODE_HOME and enter the profile to edit the environment variable.

Copy codeThe Code is as follows: vim/etc/profile

Set the nodejs environment variable inExport PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROLAdd the following content to a row:

Copy codeThe Code is as follows: # set for nodejsexport NODE_HOME =/usr/local/node/0.10.24export PATH = $ NODE_HOME/bin: $ PATH

: Wq save and exit. Compile/etc/profile to make the configuration take effect.

Copy codeThe Code is as follows: source/etc/profile

Verify whether the configuration is successfully installed

Copy codeThe Code is as follows: node-v

V0.10.24 indicates that the configuration is successful.

Npm module installation path

Copy codeThe Code is as follows:/usr/local/node/0.10.24/lib/node_modules/

Note:The official node. js website provides compiled Linux Binary packages. You can download them and apply them directly.


How to Develop nodejs on windows?

Node. js is implemented in windows. Please download it from node.org on its official website. You can use both exe and msi.
The installation is the same as the normal software installation after the download. Usage:
Open in the Start menu and select Node. js command prompt. It automatically adds environment variables to you and can directly use node and npm commands.
Node command: node (Space) js program. Use an absolute address. You can use node-h to view other parameters.
Npm command: npm is the command for node to install a third-party module. Use the simple npm install Module name. You can use npm-h to view other parameters.
All npm modules must be registered on npm.org.
In addition, cnodejs.org is a good Chinese community. Chinese documents are also provided.

Another point is that the platform selection is not as good as linux. node's core event-driven mechanism is simulated in linux using the libev + libeio library, windows itself provides system calls, and the tested performance data is windows's biggest advantage. Of course, this does not affect your use of node. js in windows and linux. It is completely cross-platform!

This is a quick start guide for beginners:
1. Create a new file named first. js.
2. Write in the file:
Var http = require ('http'); http. createServer (function (request, response) {response. writeHead (200, {'content-type': 'text/plain '}); response. end ('Hello World \ n ');}). listen (8124); console. log ('server running at localhost'); 3. After the command is input and run wildly, the "Server running at localhost" will be displayed in the "small black box". at this time, enter localhost: 8124 to display Hello World. In this way, a simple web server is built.


Nodejs programs can only be run through command lines in windows. How can they be loaded into the service?

For programmers, the command line is sufficient.

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.