2
我成功安裝了node.js和now.js。now.js:嘗試啓動server.js時出現「Object has no method」錯誤消息
對於now.js,我這是怎麼做的:
npm install now -g
npm install now (had to add this one. Without it, I get a "Cannot find now..." error message)
當我啓動節點服務器,並提供一個server.js文件是這樣的:
var httpServer = require('http');
httpServer.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Node is ok');
res.end();
}).listen(8080);
console.log('Server runs on http://xxxxx:8080/');
一切都很好。現在
,我想添加到該文件中的基本使用now.js的:
var nowjs = require("now");
var everyone = nowjs.initialize(httpServer);
everyone.now.logStuff = function(msg){
console.log(msg);
}
創建在同一文件夾中的index.html文件(用於測試目的)
<script type="text/javascript" src="nowjs/now.js"></script>
<script type="text/javascript">
now.ready(function(){
now.logStuff("Now is ok");
});
</script>
這一次,這是我得到的終端上啓動服務器時:
Server runs on http://xxxxx:8080/
[TypeError: Object #<Object> has no method 'listeners']
TypeError: Object #<Object> has no method 'listeners'
at Object.wrapServer (/home/xxxx/node_modules/now/lib/fileServer.js:23:29)
at [object Object].initialize (/home/xxxx/node_modules/now/lib/now.js:181:14)
at Object.<anonymous> (/home/xxxx/server.js:10:22)
at Module._compile (module.js:444:26)
at Object..js (module.js:462:10)
at Module.load (module.js:351:32)
at Function._load (module.js:309:12)
at module.js:482:10
at EventEmitter._tickCallback (node.js:245:11)
請記住我絕對是初學者。
謝謝您的幫助
幾件事情:1)最好不要安裝使用-g標誌,安裝他們在本地項目中,最好使用package.json文件。 2)now.ready回調被調用了嗎? 3)現在是js/now.js加載?也許試試/nowjs/now.js。 – 2012-04-22 13:45:42
所以你在服務器端收到這個錯誤? – 2012-04-25 03:40:47