第一步:
官网下载压缩包:$wget http://nodejs.org/dist/v0.12.3/node-v0.12.3.tar.gz
解压压缩包: $tar zxvf node-v0.12.3.tar.gz
配置文件: $./configure
安装: $sudo make && make install
完成之后通过 node -v 查看是否安装成功。
第二步:
安装express: npm install -g express
这个时候看不了版本号,执行:$sudo npm install express-generator
完成之后查看版本: express -V
第三步:
启动第一个项目:
(1).创建项目:$express -e testProject
(2).运行第一个nodejs程序:在testProject项目中创建example.js 编辑代码:
var
http = require(
'http'
);
http.createServer(
function
(req, res) {
res.writeHead(200, {
'Content-Type'
:
'text/plain'
});
res.end(
'Hello Node.js'
);
}).listen(8124,
"127.0.0.1"
);
console.log(
'Server running at http://127.0.0.1:8124/'
);
(3).终端运行命令:node example.js
打开浏览器,就可以看见 Hello Node.js