调用 node app.js 时出错,[node js socket io]如何修复?
cd/home/admin/web/my-doamin-name/public_html
npm 初始化
npm install --save express socket.io
node app.js
................................................ ...................
但还是显示这个错误
/home/admin/web/my-domain-name/public_html/app.js:9
consloe.log('start server on port :3000');
^
ReferenceError: consloe is not defined
at Server.<anonymous> (/home/admin/web/my-domain-name/public_html/app.js:9:2)
at Server.g (events.js:260:16)
at emitNone (events.js:67:13)
at Server.emit (events.js:166:7)
at emitListeningNT (net.js:1257:10)
at nextTickCallbackWith1Arg (node.js:431:9)
at process._tickCallback (node.js:353:17)
at Function.Module.runMain (module.js:443:11)
at startup (node.js:139:18)
at node.js:968:3
................................................ ......
应用程序.js
var app = require('express')();
var http = require('https').Server(app);
app.get('/', function(req, res){
res.sendfile('index.html');
});
http.listen(3000, function(){
consloe.log('start server on port :3000');
});
................................................ …………
index.html
<html>
<head></head>
<body>HELLO WORLD</body>
</html>
当我尝试访问 mydomain.com:3000
时,它不起作用,我该怎么办?
最佳答案
我不认为你在使用 express 时需要使用 http 模块。
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.sendfile('index.html');
});
app.listen(3000, ()=>{
console.log("The server is listening at port: 3000")
})
关于node.js - 调用 node app.js 时出错,[node js socket io]如何修复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50087205/