1. if (path === "/") {
    2. response.statusCode = 200;
    3. response.setHeader("Content-Type", "text/html;charset=utf-8");
    4. response.write(`
    5. <!DOCTYPE html>
    6. <head>
    7. <link rel="stylesheet" href="/style.css">
    8. </head>
    9. <h1>哈哈哈</h1>
    10. `);
    11. response.end();
    12. } else if (path === "/style.css") {
    13. response.statusCode = 200;
    14. response.setHeader("Content-Type", "text/css;charset=utf-8");
    15. response.write(`h1{color: red;}`);
    16. response.end();
    17. } else {
    18. response.statusCode = 404;
    19. response.setHeader("Content-Type", "text/html;charset=utf-8");
    20. response.write("你访问的页面不存在");
    21. response.end();
    22. }

    开启服务:node server.js 8888
    发请求:
    curl -v http://localhost:8888/
    curl -v -X post http://localhost:8888/