None.js 第一步 开启一个服务 hello world

  • 引入 http 模块
    var http = require('http');
  • 创建服务器

    http.createServer(function (request, response) {
        // 发送一个状态为200的请求头,内容类型为 text/plain【文本】
        response.writeHead(200, {'Content-type' : 'text/plain'});

        // 发送响应数据
        response.end("hello world");
    }).listen(9999)

    console.log('Server running at http://127.0.0.1:9999/');
posted @ 2018-02-08 15:31  小数  阅读(341)  评论(0编辑  收藏  举报