()

时间:2017-07-10 12:56:33

标签: javascript node.js intellij-idea

此代码在服务器中运行。我正在服务器上创建一个简单的websocket,它会查找与之建立的连接。但是,IntelliJ无法识别在io上调用的on()方法。我在Node.js中使用IntelliJ最新版本和编码

var http = require('http');
var express = require('express');
var socket = require('socket.io');

function onRequest(req,res)
{
    console.log('User requested for page: ',req.url);
}

// create a middleware application
var app = express();
app.use(onRequest);

// serve static files
app.use(express.static('public'));

var server = http.createServer(app).listen(4000);

// setup the socket on the server
var io = socket(server);
io.on('connection',function(socket)
{
    console.log('Socket id is: ',socket.id);
});

1 个答案:

答案 0 :(得分:3)

试试npm install @types/socket.io。它将添加必要的定义文件。