

- Cli option to debug node script in chrome devtools how to#
- Cli option to debug node script in chrome devtools code#
Cli option to debug node script in chrome devtools code#
If you want to debug code in your gatsby-node.js or your local plugins, pick your project directory. You need to add those using the “Add folder to workspace” button and pick the directory with the code you want to debug. Right now you can’t see your files in Sources. You should see Chrome DevTools start and that code execution is paused at the start of the gatsby.js entry file: Open chrome://inspect in Chrome browser and connect to a “Remote Target” by clicking the inspect link: In your project directory with the global Gatsby CLI installed run the following command: Connecting DevTools Chrome DevTools for Node Running Gatsby with the inspect flag Note: If the breakpoint is not being hit on const value = createFilePath() Using VS Code’s integrated terminal run node -nolazy node_modules/.bin/gatsby develop -inspect-brk instead of gatsby develop or node -nolazy -inspect-brk node_modules/.bin/gatsby build instead of gatsby build Make sure the Auto Attach option is set to on. Press Ctrl +, or ⌘ +, to open your preferences. If you use VS Code and its integrated terminal, you can configure it to automatically create the debug config for you. At client-side runtime, the browser’s console.log API will add messages to the developer tools console. Generally speaking, Node.js is responsible for building Gatsby pages and therefore its built-in objects like console can be used at build time. To read more about Gatsby’s build process, check out the differences between build and runtime. There you might notice that args contains a lower-cased node variable. This works similar to how you might be used to in the browser.Īdding a console.log statement in the sample from above will print the variable into your terminal.

One of the fastest ways to gain insight into Gatsby’s build process is using the console functionality built into Node.js. There is a bug in this code and using it will produce the error below: Debugging with Node.js’ built-in console
Cli option to debug node script in chrome devtools how to#
In this guide you will learn how to debug some code using various techniques.Īs an example consider the following code snippet in a gatsby-node.js file: Gatsby’s build and develop steps run as a Node.js application which you can debug using standard tools for Node.js applications.
