Using node.js as a simple web server

后端 未结 30 2221
感情败类
感情败类 2020-11-22 02:54

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same

30条回答
  •  时光说笑
    2020-11-22 03:11

    var http = require('http');
    var fs = require('fs');
    var index = fs.readFileSync('index.html');
    
    http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'html'});
    res.end(index);
    }).listen(9615);
    
    //Just Change The CONTENT TYPE to 'html'
    

提交回复
热议问题