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