Node.js安装与配置


Node.js是一套用来编写高性能网络服务器的JavaScript工具包,一系列的变化由此开始。比较独特的是,Node.js会假设在POSIX环境下运行Linux 或 Mac OS X。如果是在Windows下,那就需要安装MinGW以获得一个仿POSIX的环境。在Node中,Http是首要的。Node为创建http服务器作了优化,所以在网上看到的大部分示例和库都是集中在web上。

本文只是node.js的简单安装与配置,注意此版本的nodejs安装python2.7

安装python2.7

1.去官网下载python2.7

http://python.org

2.解压与编译

tar xvf Python-2.7.5.tar.bz2

cd Python-2.7.5

./configure --prefix=/usr/local/python2.7

make&&make install

ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7 #做一个链接,或者吧/usr/local/python2.7/bin/加到PATH变量中

1.去官网下载nodejs v0.10.7安装包,注意选择INSTALL

2.解压与编译

tar xvf node-v0.10.7.tar.gz

cd node-v0.10.7

./configure

make&&make install

3.编写一个js文件

#vim test.js

var http = require('http');


http.createServer(function (req, res) {

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

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

}).listen(8080, "127.0.0.1");

console.log('Server running at http://127.0.0.1:8080/');

node test.js & #后台运行

4.访问

elinks http://127.0.0.1:8080/

这时候应该就可以看到hello world了

更多关于Node.js的详细信息,或者下载地址请点这里

相关内容