node.js·创建http服务请求

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
612 Views
分享你的喜爱
linwute
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注