【问题标题】:Error when call node app.js, [node js socket io]how to fixed it?调用node app.js时出错,[node js socket io]如何解决?
【发布时间】:2018-04-29 13:40:58
【问题描述】:

调用node app.js时出错,[node js socket io]如何解决?

  1. cd /home/admin/web/my-doamin-name/public_html
  2. npm init
  3. npm install --save express socket.io
  4. 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

.................................................. …………

app.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 时,它不起作用,我该怎么办?

【问题讨论】:

  • consloe.log => console.log

标签: node.js linux websocket socket.io centos7


【解决方案1】:

我认为在使用 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")
})

【讨论】:

    猜你喜欢
    • 2014-10-18
    • 2017-08-07
    • 2015-12-24
    • 1970-01-01
    • 2013-04-20
    • 2016-04-20
    • 1970-01-01
    • 2015-03-23
    • 2018-12-13
    相关资源
    最近更新 更多