node 1.开启应用

夙愿已清 提交于 2020-03-18 07:32:42

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!