2016-07-22 16 views
-1

我正在學習Node.js。我如何使用node.js刷新HTML內容

我有一些問題。

var http = requite('http'); 
var server = http.createServer(function(req, res) { 
      res.writeHead(200, {'Content-Type': 'image/png'}); 
      res.end(lastPng); 
}); 

這是我的代碼。我想重新加載瀏覽器(localhost:8080)。

我該怎麼做?

+2

這個代碼是沒有意義的。 lastPng沒有在任何地方定義,你實際上並沒有聽任何東西......並且你不能從服務器重新加載瀏覽器頁面,而沒有嚴重的skulldugegery。 – Paul

+0

嘗試使用重新加載npm模塊參考[鏈接](https://www.npmjs.com/package/reload) – Thennarasan

+0

對不起...一些代碼丟失 – Ryu

回答

0

爲了讓你開始嘗試下面的代碼:

var http = require('http'); // note that you had a typo here 'requite' 
var server = http.createServer(function(req, res) { 
     // Changed the content type to text/plain for demo 
     res.writeHead(200, {'Content-Type': 'text/plain'}); 
     // Now you are rendering 'Hello World' 
     res.end('Hello World'); 
}); 
// You need to start your server listening on port 8080 
server.listen(8080); 

如果你去http://localhost:8080你會看到文本的「Hello World」