我從頭做到了這一點,它仍然給了我一個錯誤...Express將不會發送標題
我已經運行
express test
然後
cd test && npm install
我已編輯app.js添加這樣的路線:
app.get('/test',function(req,res) {
res.writeHead(200, {"Content-Type": "application/json"});
return res.send('{"a":3}');
});
然後,我' E運行節點
node app.js
,當我嘗試訪問http://server/test我得到
Error: Can't set headers after they are sent.
我使用 節點V4.2.1,快速2.5.8,3.4.0 NPM。
這只是發生在Express,如果我在節點上創建一個簡單的服務器,我可以使用writeHead。
如果你從頭開始做這個,爲什麼在你使用的是2.x版本?!?!它自2012年以來一直未更新。 – cdbajorin