Install nodejs 0.9.0 in centos 6

Source: Internet
Author: User
Tags print print

Ensure that python is installed. Most installation failures are caused by the low Python version. Before installation, upgrade python to http://www.tomtalk.net/wiki/python.

[Root @ SNDA-192-168-15-161 ~] # Python-V
Python 2.7.3
Start installation:

1) download nodejs to the local device and decompress it.
[Root @ SNDA-192-168-15-161 node] # wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz
[Root @ SNDA-192-168-15-161 node] # tar zxvf node-v0.9.0.tar.gz
2). Go to the directory to compile and install
[Root @ SNDA-192-168-15-161 node-v0.9.0] # cd node-v0.9.0
[Root @ SNDA-192-168-15-161 node-v0.9.0] #./configure -- prefix =/usr/local/node/0.9.0
It is installed in the/usr/local/node/0.9.0 directory.
[Root @ SNDA-192-168-15-161] # Make
[Root @ SNDA-192-168-15-161] # make install
3) Configure node_home
[Root @ SNDA-192-168-15-161] # vi/etc/profile
In export path user... Add the following content to the line and set node_home/bin to the system path.
# Set for nodejs
Export node_home =/usr/local/node/0.9.0
Export Path = $ node_home/bin: $ path
Save and exit, and execute the following command to make the configuration take effect.
[Root @ SNDA-192-168-15-161] # source/etc/profile

Run the node-H command to verify that the setting is successful.

[root @ SNDA-192-168-15-161 ~] # Node-H
usage: node [Options] [-E script | script. js] [arguments]
node debug script. js [arguments]

options:
-V, -- version print node's version
-E, -- eval script evaluate script
-P, -- Print print result of -- eval
-I, -- Interactive always enter the repl even if stdin
does not appear to be a terminal
-- no-deprecation silence deprecation warnings
-- Trace-deprecation show stack traces on deprecations
-- v8-options print V8 command line options
-- Max-Stack-size = Val Set max V8 stack size (bytes)

Environment variables:
Node_path ':'-separated list of directories
Prefixed to the module search path.
Node_module_contexts set to 1 to load modules in their own
Global contexts.
Node_disable_colors set to 1 to disable colors in the repl

Documentation can be found at a http://nodejs.org/
So far, the installation and configuration are complete.

Run a simple node ApplicationProgram+ Socket. Io, the socket. Io module must be installed first.

[Root @ SNDA-192-168-15-161 ~] # NPM install socket. Io

[Root @ SNDA-192-168-15-161 ~] # Vi app. js

VaR HTTP = require ('http ');
VaR IO = require ('socket. Io ');
VaR Server = http. createserver (function (req, Res ){

Res. writehead (200, {'content-type': 'text/plain '});
Res. End ('Hello World ');
});

Server. Listen (process. argv [2]);

VaR socket = Io. Listen (server );
Socket. On ('connection', function (client ){
Console. Log ('client has connected ');
Client. On ('message', function (){});
});
 

[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8001 &

[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8002 &

[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8003 &

[Root @ SNDA-192-168-15-161 ~] # Nodejs./APP. js 8004 &

For more details, refer to the example on the socket. Io official website.

Perfect Combination of websocket and node. js

http://wanshuiqianshan.iteye.com/blog/1618498

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.