创建 nodejs HTTP服务器

来源:互联网 发布:脑图软件 mac 编辑:程序博客网 时间:2024/05/19 11:46
1.加载代码
var http = require('http');http.createServer(function (request, response) {  response.writeHead(200, {'Content-Type': 'text/plain'});  response.end('Hello World\n');}).listen(8888);console.log('Server running at http://127.0.0.1:8888/');
其中 require为加载 http 模块,调用 http 模块的 createServer 方法,返回的对象再调用 listen 方法

2.在浏览器中 输入 ip:8888

0 0
原创粉丝点击