2012-04-21 5 views
2

node.js와 now.js가 성공적으로 설치되었습니다.now.js : server.js를 시작하려고 할 때 "객체에 메서드가 없습니다"라는 오류 메시지가 표시됩니다.

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/'); 

모든 것이 괜찮습니다.

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> 
:

지금, 나는이 파일에 now.js의 기본적인 사용을 추가하기 위해 노력하고있어

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

몇 가지, 설치 프로젝트에서 로컬로, 바람직하게는 package.json 파일을 사용합니다. 2) now.ready 콜백이 호출됩니까? 3) nowjs/now.js가로드 되었습니까? 아마도 /nowjs/now.js를 시도해보십시오. –

+0

서버 측에서이 오류가 발생합니까? –

답변

1

'NPM -g 설치'글로벌 수준의 모듈을 설치 주셔서 감사합니다. Ruby Gems를 생각해보십시오. 모듈을 프로젝트의 일부로 포함 시키려면 -g를 제거해야합니다.

또한 httpServer 변수는 서버가 아니라 http 모듈입니다. createServer()는 다음과 같이) 당신의 nowjs.initialize (에서 사용할 변수와 방법을 캡처 할 서버 개체 반환 : 1) 가장 -g 플래그를 설치하지

var http = require('http') 
    , now = require('now') 

// Returns an Http Server which can now be referenced as 'app' from now on 
var app = http.createServer(
    //... blah blah blah 
) 

// listen() doesn't return a server object so don't pass this method call 
//  as the parameter to the initialize method below 
app.listen(8080, function() { 
    console.log('Server listening on port %d', app.address().port) 
}) 

// Initialize NowJS with the Http Server object as intended 
var everyone = nowjs.initialize(app)