我剛剛開始使用Socket.IO,但無法正常運行。她的字碼要求(...)不是函數
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...
我試過你說的TypeError:app.get不是函數 在Object。在Module._compile(module.js:571:32) (在Object.Module中) (I:\ Bilal \ Aptech \ Tutorials Point Practice \ Socket.IO \ Chapter 1 - Hello World \ app.js:4:5)在module.load(module.js:488:32) at tryModuleLoad(module.js:447:12) at Function.Module._load(module。)._extensions.js(module.js:580:10) at Module.load (bootstrap_node.js:423:7) at bootstrap_node.js:bootstrap_node.js:147:9) : 538:3 –
請參閱https://www.tutorialspoint.com/socket.io/socket.io_hello_world.htm。我的代碼是一樣的!! –
它的工作!將它標記爲答案很快:)非常感謝:) –