// 引用http插件
var http = require('http');
// 开启node服务
var server = http.createServer();
// 监听开始
server.on('listening', function () {
console.log('listen..');
});
// 客户端请求
server.on('request', function (req,res) {
//console.log('请求了');
// 返回状态位、显示纯文本、html
res.writeHead(200, '1', {
'content-type': 'text/plain',
// 'content-type': 'text/html;charset=utf-8'
});
res.write('
hello world!
');
res.end();
});
// 监听8080端口
server.listen(8021, 'localhost');