好玩的.HTML传输

版权声明:个人笔记,不喜勿喷 https://blog.csdn.net/qq_39571197/article/details/88572627
const http = require('http');
const { exec } = require('child_process');
const app = http.createServer(router), port = 8080;
app.listen(port, function () {
    exec(`start http://localhost:${port}`);
});
function router(req, res) {
    let count = 10;
    res.write(`<!DOCTYPE html>`); // 核心,声明是一个文档,浏览器就会开始加载了(不然会一直白屏)
    setInterval(function () {
        if (!count) {
            return res.end('hello');
        }
        res.write(String(count--));
    }, 1000);
}

 

没有更多推荐了,返回首页