安装
https://nodejs.org/en/download/
建议用安装包
1
2
3
4
5
6
7
8
9
10
|
环境
yum install -y gcc-c++ make
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
老版本先删除
yum remove -y nodejs npm
安装
yum -y install nodejs
|
1
2
3
4
5
| yum remove nodejs npm -y
- 清理目录
/usr/local/lib
/usr/local/include
|
1
2
3
4
5
| sudo npm cache clean -f
sudo npm install -g n
sudo n 6.11.00
or
sudo n stable
|
测试环境 helloword
1
| console.log("helloword!");
|
创建一个 web server
1
2
3
4
5
6
7
| var http = require("http")
http.createServer(function(request, response){
response.writeHead(200,{'content-Type':'text/plain'});
response.end('hello word!');
}).listen(8888);
console.log('web server is running! http://127.0.0.1:8888/');
|
调用
模块
服务
监听在 8888 端口
浏览器输入 http://127.0.0.1:8888/
参考
https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/
代码
https://github.com/hans007/JavaScriptCodes/tree/master/nodejs-do
我的博客