Install and use node. js in Linux (centos6.0)

Source: Internet
Author: User
Tags install node
Install node. js in centos6.0

1. wget http://nodejs.org/dist/node-v0.6.9.tar.gz
Tar zxvf node-v0.6.9.tar.gz
CD node-v0.6.9
./Configure -- prefix =/usr/local/node ---------- installation prompt ------------- checking for program g ++ or C ++: not found
Checking for program ICPC: not found
Checking for program c ++: Not found ---------------------------- Yum install gcc-C ++ can solve -----------------------------
Make
Make install
2. Test
Create the test. js file with the following content:
VaR HTTP = require ('http ');
HTTP. createserver (function (req, Res ){
Res. writehead (200, {'content-type': 'text/plain '});
Res. End ('Hello world \ n ');
}). Listen (1337, "127.0.0.1 ");
Console. Log ('server running at http: // 127.0.0.1: 1337 /');

Run node test. js.

#/Usr/local/node/bin/node/www/test. js


Enter http: // 127.0.0.1: 1337/in the browser. The "Hello World" text indicates that the installation is successful! Note that the file name cannot be added later.

Note:

1. The client can only be accessed through the port, and the JS file name cannot be specified.
2. The listening IP address can be omitted so that access can be made anywhere. If 127.0.0.1 is specified, access can only be made on the local machine!

If you want to access other machines in the LAN or the Internet, you need to modify the listening IP address that has been port. The secondary port must be enabled on the firewall, for example, port 80, if this port is occupied, You need to enable other ports var HTTP = require ('http ');
HTTP. createserver (function (req, Res ){
Res. writehead (200, {'content-type': 'text/plain '});
Res. End ('Hello world \ n ');
}). Listen (80, "192.168.1.100 ");
Console. Log ('server running at http: // 192.168.1.100: 80 /');-------------------------------------------

Note: If you want to output HTML code to the browser, set Content-Type to text/html. If it is set to text/plain, only the text is output.

Response. writehead (200, {"Content-Type": "text/html; chartset: UTF-8 "});

-------------------------------------------- Reference: http://www.cnblogs.com/rubylouvre/archive/2010/07/15/1778403.htmlhttp://www.cnodejs.org/http://club.cnodejs.org/topic/4f16442ccae1f4aa27001071

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.