node.js

95 阅读1分钟

1.第一个 node 应用

var http = require('http');
// 1.创建服务
http.createServer(function (request, response) {

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

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

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

image.png

image.png webpack 开发者模式的服务就是在本地内置了一个 express 服务