http.createServer


const http = require('http'); // Node.js 内置的 http 模块

/**

  • 请求事件发生时调用的回调函数 (Node.js 是执行单线程异步非阻塞事件驱动的)
    */
    function requestListener(req, rep) {
    console.log("Request received."); // 当我们启动服务器访问网页时, 服务器可能会输出两次 'Request received.', 那是因为大部分浏览器都会在你访问 http://localhost:8080/ 时尝试读取 http://localhost:8888/favicon.ico 站点图标
    rep.writeHead(200, {'Content-Type':'text/html'}); // 响应头
    rep.write('

    Hello World

    '); // 响应主体
    rep.end(); // 完成响应
    }

/**

console.log("Server has started.");


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM