16

When I run nodemon dist/server/app.js it works on default port 3000 and I'm able to reach my API. But if I run

nodemon --inspect-brk=localhost:3000 dist/server/app.js

I got error

WebSockets request was expected

What's wrong?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
ycshao
  • 1,768
  • 4
  • 18
  • 32
  • 1
    You can't run the debugger and your server on the same port. Using `--inspect-brk=localhost:3000` tells it to run the debugger on port 3000 which is where your server already is. Why are you passing a port number for `--inspect-brk` at all? – jfriend00 Apr 11 '18 at 04:44
  • @jfriend00, I didn't run them at the same time, I tried to run debugger on the same port like the way I run my server without debugger. Because my client is using port 3000 to reach my server. – ycshao Apr 12 '18 at 03:04
  • 2
    @jfriend00, I think I got what you meant, `--inspect-brk=localhost:3000` will try to attach debugger to the same port as the server is running. I didn't realize server and debugger are different process. – ycshao Apr 12 '18 at 03:15
  • Yeah, the debugger is yet another server, built into the node.js runtime. – jfriend00 Apr 12 '18 at 03:19

1 Answers1

19

You can't run your web server and the debugger on the same port. They are each separate servers (the debugger is a server built into the node.js runtime).

So, you can either remove the port and host designation from the --inspect-brk option and just let it use the defaults (which is all I ever use) or you can select a different port for the debugger that doesn't conflict with your web server or anything else running on that host.

jfriend00
  • 683,504
  • 96
  • 985
  • 979