2017-04-27 4 views
0

지금 Socket.IO를 시작했지만 제대로 실행하지 못했습니다. 그녀는require (...)가 함수가 아닙니다.

을 app.js 코드입니다
var app = require('express')(); 
var http = require('http').Server(app); 

app.get('/', function(req, res){ 
    res.sendFile('index.html'); 
}); 

http.listen(3000, function(){ 
    console.log("Listening On Port *: 3000"); 
}); 

된 index.html은

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Hello World</title> 
    </head> 
    <body> 
     Hello World 
    </body> 
</html> 

내가 노드 또는 nodemon를 사용하여 실행하려고, 둘 다 설치하고 난 socket.io 전 세계적으로 설치 한 (v1.7.3)이이

TypeError: require(...) is not a function 
    at Object.<anonymous> (I:\Bilal\Aptech\Tutorials Point Practice\Socket.IO\Chapter 1 - Hello World\app.js:1:91) 
    at Module._compile (module.js:571:32) 
    at Object.Module._extensions..js (module.js:580:10) 
    at Module.load (module.js:488:32) 
    at tryModuleLoad (module.js:447:12) 
    at Function.Module._load (module.js:439:3) 
    at Module.runMain (module.js:605:10) 
    at run (bootstrap_node.js:423:7) 
    at startup (bootstrap_node.js:147:9) 
    at bootstrap_node.js:538:3 
[nodemon] app crashed - waiting for file changes before starting... 

답변

0

를 해결하기 위해 함수

하지 않은 null를 돌려줍니다. 이 시도 : 그렇지 않으면

var app = require('express');

을,이 시도 :

var express = require('express'); var app = express();

+0

나는 당신이 말한 것을 시도한 후 TypeError : app.get은 Object가 아닌 의 함수가 아닙니다. Object.Module에서 Module._compile (module.js : 571 : 32) (I : \ Bilal \ Aptech \ Tutorials Point Practice \ Socket.IO \ 1 장 - Hello World \ app.js : 4 : 5) Module.load (module.js : 488 : 32)의 에서 ._extensions..js (module.js : 580 : 10) tryModuleLoad (module.js : 447 : 12) at Function.Module._load (module. JS : 439 : Module.runMain (module.js에서 3) : 605 : 10) 실행 (bootstrap_node.js에서 : 423 : 시작 (bootstrap_node.js에서 7) : 147 : bootstrap_node.js에서 9) : 538 : 3 –

+0

참조 : https://www.tutorialspot.com/socket.io/socket.io_hello_world.htm. 내 코드는 동일합니다 ...! –

+0

작동했습니다! 곧 답으로 표시 할 예정입니다 :) 고마워요. :) –

0

을 보여줍니다 당신은 아마 그것의 requir를 설치하지 않은 경우, 설치 명시가없는 에드 ('표현')은 당신이 마지막에 ()와 함수로 필요 호출하려고 때문입니다 생각 실행을

npm install express 
+0

내가 잘 표현 노드 응용 프로그램을 실행할 수 있습니다. 전 세계적으로 모든 모듈을 설치했고 node_modules에 NODE_PATH를 설정했습니다 –

+0

Express의 구버전이 될 수 있습니까? 난 그냥 내 시스템에 코드를 tryed 및 그것은 perfired 함께 설치된 익스프레스, 어쩌면 시도해도 console.log (typeof require ('express')); 반환되는 내용이 표시되어야합니다. –

+0

실행하기 전에 node_modules를 업데이트했습니다! :) –

관련 문제