> CentOS > CentOS教程 >

centos nodejs

# cat /etc/redhat-release

  CentOS release 6.2 (Final)

# wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm

  Saving to: “nodejs-stable-release.noarch.rpm”

# rpm -qlp nodejs-stable-release.noarch.rpm

  /etc/pki/rpm-gpg/RPM-GPG-KEY-nodejs-stable-el-5
  /etc/yum.repos.d/nodejs-stable.repo

# yum localinstall  nodejs-stable-release.noarch.rpm

  Installed: nodejs-stable-release.noarch 0:5-3                                           

# yum list \*node\*

  nodejs-stable
  nodejs-stable/primary_db

  Installed Packages
  nodejs-stable-release.noarch  5-3  @/nodejs-stable-release.noarch

  Available Packages
  ...
  nodejs.i686  0.6.6-1.el6  nodejs-stable
  ...

# yum install nodejs

  Installed: nodejs.i686 0:0.6.6-1.el6

  Dependency Installed: libicu.i686 0:4.2.1-9.1.el6_2 v8.i686 0:3.6.6.11-1.el#
# yum list \*npm\*
# yum install npm

# cat example.js

  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/');

# nodejs example.js

  Server running at http://127.0.0.1:1337/

$ wget http://localhost:1337/any

$ cat any

  Hello World

# cat serv.js

  var net = require('net');

  var server = net.createServer(function (socket) {
    socket.write("Echo server\r\n");
    socket.pipe(socket);
  });

  server.listen(1337);  // any IP address


#ls -s /usr/bin/nodejs /usr/bin/node
#npm install express -g


(责任编辑:IT)