--- tags: ironhack --- [:fr: version française](https://hackmd.io/s/BJ60qRS4E) Node.js debugger into VS Code === ## `node --inspect` To enable Node's debug mode, we should execute `node` with the [`--inspect`](https://nodejs.org/api/debugger.html) flag. Let's add that flag to our `npm run dev` script into `package.json` file, generated by [`irongenerate`](https://www.npmjs.com/package/iron-generator): ```json=7 "dev": "DEBUG=starter-code:* nodemon --inspect ./bin/www" ``` :::info :bulb: Without having to modify that line, we can also pass the flag by executing the command `npm run dev -- --inspect` but it's longer :smiley: and we have to remember it every time (see the [npm-run-script](https://docs.npmjs.com/cli/run-script.html) doc about.) ::: ## `Auto Attach` In VS Code's preferences, we set the `Node: Auto Attach` setting to `on`: ![](https://i.imgur.com/Y7AWdly.png) ## Debug now🐛 **From a VS Code terminal**, we now launch the command `npm run dev`: ![](https://i.imgur.com/8zPbfaf.png) > The command outputs: `Debugger listening on port 9229.` We can now set some breakpoints, by clicking on the line we want to debug: ![](https://i.imgur.com/8IVOYZo.png) > 🔴 The red point to the left of the line 71 indicates that a breakpoint is now set to. --- When a request will call that line of code, the debugger will pause the program and will allow us to inspect our variables values, do some step-by-step... etc: ![](https://i.imgur.com/4LTf1BN.png) ## devTools alternative If we don't want to use VS Code to debug, Chrome devTools is also possible: - Go to URL: [`chrome://inspect`](chrome://inspect) ![](https://i.imgur.com/TWOoDa1.png) - then click on the `inspect` link on the corresponding remote target : ![](https://i.imgur.com/aaDx7mH.png)