(Note: I moved this info into the main FxA readme at https://github.com/mozilla/fxa.)
Attaching a debugger to a running node process, sadly, requires running google chrome (AFAIK).
How to do it:
-
Start google chrome and open up
chrome://inspect
. -
Run a node process using the
--inspect
or--inspect-brk
flags (see specific command-line incantations below) -
In chrome, you should see the process show up in the Remote Target pane with an 'inspect' link. Click it to jump into the debugger.
For jest, you'll want to pass the --runInBand
argument, so it doesn't fork off the test runner to a separate process (that isn't available to the inspector).
node --inspect-brk ./node_modules/.bin/jest --runInBand --config server/jest.config.js filematcher
where filematcher is a partial regex that matches the test you want to debug. If you omit filematcher
, it'll just run all tests.
For mocha, you'll want to pass the --timeout 0
option, otherwise the test will fail if you step through it and exceed the default timeout (currently 2 seconds on fxa-shared).
node --inspect-brk ./node_modules/.bin/mocha --timeout 0 path/to/file
Theoretically, it should be easy to do this with pm2 (Danny suggested ./pm2 sendSignal SIGUSR1 $id
, where $id is the pm2 id) . I haven't gotten that working yet.
Here's what has worked for me:
- Start the whole server as usual (
npm install && npm start
from top-level in the monorepo) - Stop the pm2-managed version of whatever server you care about,
./pm2 stop NN
where NN is the pm2id
listed when you do./pm2 ls
. Not thepid
. - Start the server in a special per-server way:
Start the server with npm run start-dev-debug
. You should see the process pop up in the chrome://inspect
panel in google chrome. You're off to the races, either set a breakpoint or add the debugger;
operator to the code you want tto debug.
Start the server with npm run start-dev-debug
.