一、http模块、url模块、supervisor工具
http模块
var http = require(‘http’);
http.createServer(function(request, response){
response.writeHead(200, {’'Content-Type": “text/plain”});
response.end(“hello world”);
}).listen(8081);
http.createServer // 创建应用
request // 浏览器传到应用的信息
response // 给浏览器响应信息
writeHead // 设置响应头
end // 页面上输出 并且结束响应应用
listen(num) num // 端口
服务器解决乱码: response.writeHead(200, {’‘Content-Type": “text/html;charset=‘utf-8’”})
浏览器解决乱码: response.write(’’)
URL模块
url.parse(); 解析地址 接收两个参数 (api, boolean) boolean是否要将参数转话为json格式
supervisor
自动加载服务端工具
cnpm install supervisor -g
一般是node app.js
那么就用supervisor app.js