node.js·创建http服务请求
node·创建http服务请求
运行方式:终端运行 node xxxx.js
1】固定格式
var httpReauire = require('http'); //引入模块 httpReauire.createServer(function(reauire, response) { response.writeHead(200, {//请求头 'Content-Type': 'text/plain' }); //发送数据 response.end('第一个http服务'); }).listen(5249); //端口 console.log("运行了");
2】输出字母
//输出字母 Buffer.alloc(26); 是固定的 var buf = Buffer.alloc(26); var bufx = Buffer.alloc(26); for (var i = 0; i < 26; i++) { buf[i] = i + 65; bufx[i] = i + 97; } console.log(buf.toString()); //ABCDEFGHIJKLMNOPQRSTUVWXYZ console.log(bufx.toString()); abcdefghijklmnopqrstuvwxyz
996 Views