Monday, 1 April 2019

How to debug only socket.io connection without Node.js site in WebStorm/PhpStorm?

I'm developing a site which is in PHP. In this website I'm creating chat. Now problem is that I can't debug properly in WebStorm/PhpStorm.

This is command which I was using now in cmd before

node -r dotenv/config server.js

for debugging I'm using console.log which will write socket server data in cmd and client side socket data in browser console.

I want to shift to IDE debugging. I use PhpStorm and sometimes WebStorm. Both are same in JavaScript handling.

This is configuration I've done in PhpStorm:

Nodejs Debug configuration

The problem is breakpoint is not working on socket receiver in server.js

const express = require("express");
const app = express();
const serverConf = require("./serverConf");
const server = serverConf.createServer(app);
const io = require("socket.io").listen(server, {'pingTimeout': 5000, 'pingInterval': 1000});

serverConf.startServer(server);

io.on("connection", function (socket) {
    socket.on("admin_send_text", async function(response) {
        response.admin_id;
        console.log(response);
    });
});

Breakpoint is on response.admin_id line

Because I'm not using any routes so I can't debug socket connection. It's just move to next line. Like no breakpoint is there.

This is a message I receive in terminal

"C:\Program Files\nodejs\node.exe" -r dotenv/config C:\xampp\htdocs\gofashion\chat\server.js DEBUG=*
Debugger listening on ws://127.0.0.1:61037/1e06be2f-b94f-41c4-bbc8-a7437dcd2d4d
For help, see: https://nodejs.org/en/docs/inspector

How to do I set breakpoint on socket receiver on server?



from How to debug only socket.io connection without Node.js site in WebStorm/PhpStorm?

No comments:

Post a Comment