node 1.开启应用

// 引用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');

posted @ 2018-04-24 21:58  福小松  阅读(156)  评论(0编辑  收藏  举报