Node.js_Linux安装

介绍linux下的安装,Node在Linux环境下的安装和使用都非常方便,建议在Linux下运行Node, 我使用的是Ubuntu


安装依赖包:

sudo apt-get install g++ curl libssl-dev apache2-utils

sudo apt-get install git-core 



在终端一步步运行一下命令:
git clone git://github.com/joyent/node.git

cd node

./confirgure

make #(时间有点长)

sudo make install



这样子node.js就安装完成。


测试一下:

vi helloWorld.js

  
console.log('Hello World');


node helloWorld.js

  
Hello World


即完成安装。


启动服务:

vi server.js

  
var http = require('http');

   http.createServer(

       function(req,res){

          res.writeHead(200,{'Content-Type':'text-plain'});

          res.end('Hello World\n');

       }

   ).listen(10086,"localhost");

   console.log('Server running at http://localhost:1337');



node server.js

   如果成功,则控制台打印:
Server running at http://localhost:1337


   如果端口冲突,则控制台打印:

  
events.js:77

        throw er; // Unhandled 'error' event

              ^

   Error: listen EADDRINUSE

      at errnoException (net.js:928:11)

      at Server._listen2 (net.js:1066:14)

      at listen (net.js:1088:10)

      at net.js:1162:9

      at asyncCallback (dns.js:68:16)

      at Object.onanswer [as oncomplete] (dns.js:121:9)



你可能感兴趣的:(node.js)