azl397985856 / fe-interview

宇宙最强的前端面试指南 (https://lucifer.ren/fe-interview)
Apache License 2.0
2.85k stars 260 forks source link

【每日一题】– 2019-10-25 - 如果一个 Node.js 进程已经启动,没有添加 --inspect 参数,我们不想重启(会丢失现场)又想调试怎么办? #47

Closed azl397985856 closed 5 years ago

azl397985856 commented 5 years ago

node --inspect app.js 可以用来调试应用,但是需要在一开始启动的时候指定--inspect参数,如果一个 Node.js 进程已经启动该怎么办?

azl397985856 commented 5 years ago

Intuition

Actually, if u'r familiar with attach mode in VSCode, it will be very comfortable for u.

Two Ways

Below is the detailed info:

  1. node -e

-e, --eval=... evaluate script

node -e 'process._debugProcess(30464)'
  1. system signal
$ kill -SIGUSR1 30464