Hit the debugging icon in the left column menu, and to add a NodeJS debugging option, click the down arrow and Add Configuration. You can now listen to your NodeJS application in the VS Code debugger. I found this nifty code snippet on Stack Overflow>, and have updated my index.js to this:Ĭonsole.log('Infinite Loop Test interval n:', i++) Īnd running index.js now gives me a running app that I can connect my debugger too: node -inspect index.jsĭebugger listening on ws://127.0.0.1:9229/68cf6bbe-86aa-4bf8-ae43-5e287dee7b8c Introducing an infinite loop will do the trick. If the app isn’t running, and ends too soon, we can’t connect our debugger to it. Now we need an app that is constantly running. To run our index.js file, use the inspect option. When running our commands in the terminal window with the node command, we can enable the inspector tool, which lets allows us to connect to our running NodeJS application with a debugging tool, such as Code. Installing this extension, like any other extension in VS Code is pretty straightforward, click on the Extensions icon in the left menu, search for Node Debug and install. To ensure your VS Code can connect to a NodeJS debugging session, install Node Debug extension. Lets get started by creating the simplest Node.js application, 'Hello World'. Its only natural that I need to now debug this code right in VS Code. Node.js tutorial in Visual Studio Code Hello World. With nvm, you can install multiple versions of both the Node. Click on explorer, then create a file called app.js (you can give any name) 2. I run my node scripts in the terminal window using the node CLI command. The best way to install Node.js and npm is through Node.js Version Manager, or nvm. I use VS Code to do 90% of all of my development, with VI being the other 10%. While digging into these concepts I quickly realized that while writing code examples of any kind, I was going to need a debugger. In a previous article I wrote about NodeJS async and await, in which I used real world working examples and wrote/tested all code shown in the article as I was writing.
0 Comments
Leave a Reply. |