第一步:先到官网下载并安装nodejs
安装教程路径:https://www.runoob.com/nodejs/nodejs-install-setup.html
第二步:在编译器中写好http.js文件
var http=require('http');
http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'})
res.write('hello world')
res.end()
}).listen(2015,'127.0.0.1')
res.write是输出的内容,2015是内容的端口号
第三步:在命令窗口内运行http.js
ps:要注意http.js 文件的准确位置,退出node命令按ctrl+c
第四步:在浏览器中输入准确端口号即可(http://localhost:2015/)
常见命令
url.parse, url.reslove
querystring.stringify, querystring.parse
querystring.escape, querystring.unescape转义和反转义
Chrome本地DNS缓存记录查看方法
chrome://net-internals/#dns
Github(键盘上按下t可进行检索):
https://github.com/nodejs/node
http性能测试: Apache ab
注:在window系统下,需要先用cd命令定位到你的apache安装目录的bin文件夹
1 | ab -n1000 -c10 http://localhost:2015/ |
-n :总共的请求执行数,缺省是1;
-c: 并发数,缺省是1;
-t:测试所进行的总时间,秒为单位,缺省50000s
-p:POST时的数据文件
-w: 以HTML表的格式输出结果