Node.js起一个web服务器

开启服务:

代码如下:

var http = require('http');

http.createServer(function (request, response) {

    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(8888);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');

 

posted on 2017-11-05 15:16  玉思盈蝶  阅读(567)  评论(0编辑  收藏  举报

导航