Page tree
Skip to end of metadata
Go to start of metadata

This tutorial describes how to run and debug Node.js applications in WebStorm.
Go to this tutorial for getting started with Node.js in WebStorm.

Running Node.js app locally

To run your Node.js application locally on your machine, you need to create a new Node.js Run/Debug configuration.

Click Edit configurations in the top right-hand corner of the IDE window or in the main menu Run.

Сlick + to add a new configuration and seleсt Node.js type.

Specify the path to the JavaScript file that needs to be executed. You can also add any parameters you need to pass to the node (Node parameters input) or to your application (Application parameters input) on the start.

Select this new configuration from the drop-down list on the top-right and click Run. The Run tool window with console will appear.

Running Express web app:

Starting with Express 4.0 file www.js in bin folder needs to be executed to start the app. When creating a new Express web application in WebStorm 8.0.2 or higher, the required Run/Debug configuration will be created automatically. Select configuration bin/www and click Run. Now when the app is running, you can open it in browser on localhost:<app’s server port number>.

Debugging Node.js app locally

The same Run/Debug configuration can be used to debug your Node.js code.

The built-in Node.js debugger supports the latest features of V8 Debugger Protocol and allows you to step through the breakpoints, change values on the fly, evaluate expressions, and set watches.

Click the Debug button for the created Run/Debug configuration in the top right-hand corner of the IDE, from the Run menu or with the shortcut (Shift+F9 on Windows or Linux, Ctrl+D on Mac). A tool window with variables view, frames and watchers for your debug session will appear:

Debugging Node.js app that runs remotely

With Remote Node.js Debug configuration you can debug Node.js apps that are running remotely. You’ll be able to restart the debug session without restarting the app itself.
Select Remote Node.js Debug type when creating a new debug configuration, then specify the host you need to connect to and the port.

Now that the debug configuration is ready, select it from the drop-down list of configurations on the right and click Debug.

You’ll see the Debug tool window when the breakpoint is reached. You’ll be able to use full-featured debugger in the same way as if you were debugging your code locally.

Note: For remote debugging your app should be running with the parameter --debug=<port for debugging> or --debug-brk=<port for debugging>.

In Node.js you can’t access the port for debugging externally, which is why you need to configure a proxy or any other software that ensures port forwarding on the Node.js server (for an example of how to do that see stackoverflow).

  • No labels