Saturday, May 28, 2016

Debugging Node.js with Visual Studio Code

This page will guide you on how to debugging Node.js with Visual Studio Code.
Visual Studio Code is the free code editor from Microsoft for Windows, Mac and Linux. This application provides full Node.js support with syntax highlighting, code completion and debugging.
I have been playing around for sometime and want to share how to debug Node.js project in Visual Studio Code to you.

1Create new folder, and add Node.js file inside.

2Open Visual Studio Code. Then click 'File' => 'New Window'.

3New empty project will be created. Then click 'File' => 'Open Folder'.

4Select folder that you created in step 1.

5You will see that folder is added into the application.

6Click debug menu on left side bar.

7Click 'Open launch.json' setting icon.

8Application will prompt you to select the platform environment. Select 'Node.js'.

9You will see that application will add folder '.vscode' for you which have 'launch.json' file inside. This file contains the project configuration. Make sure that 'program' attribute should be the Node.js file that you want to run on startup.

10You can place breakpoints by click on bar on the left of line number.

11Click debug mode on left side pane, and click 'Start Debugging'.

12The program will start debugging. You can also watch the variables using 'WATCH' pane, or type variable directly into 'DEBUG CONSOLE' pane. Moreover, you can inspect the call stack using 'CALL STACK' pane.



Happy Coding!

No comments:

Post a Comment