Loading basic HTML in Node.js

后端 未结 20 1345
暗喜
暗喜 2020-11-28 17:34

I\'m trying to find out how to load and render a basic HTML file so I don\'t have to write code like:

response.write(\'...

blahblahblah

...\
20条回答
  •  执笔经年
    2020-11-28 18:05

       var http = require('http');
       var fs = require('fs');
    
      http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        var readSream = fs.createReadStream('index.html','utf8')
        readSream.pipe(response);
      }).listen(3000);
    
     console.log("server is running on port number ");
    

提交回复
热议问题