Running and debugging Node.js application

Updated on June, 18 2014

Let’s continue our series of posts and tutorials on Node.js development in WebStorm.
Our first post covered the basic WebStorm configuration for working with Node.js projects. Now let’s move on to running and debugging Node.js apps both locally and remotely.

Running Node.js app locally

WebStorm allows you to run Node.js application locally on your machine: you should create a Node.js Run/Debug configuration for the file you need to execute and click Run.

To create a new Run/Debug configuration, click Edit configurations in the top right corner of the IDE window, or in the main menu Run. Click Add new configuration and seleсt Node.js type.

In this new Run/Debug configuration, specify the path to the JavaScript file that needs to be executed. For example, for a simple Express web app it should be a file that configures and starts the web server.

You can also add any parameters you need to pass to node (Node parameters input) or to your application (Application parameters input) on the start.

node-rdc

Update: 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 this new configuration and click Run. The Run tool window with console will appear showing the app execution log.

runnode2

Debugging Node.js app locally

The same 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:

node-debugger

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.

remoteconf

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.

Please note that for remote debug your app should be running with –debug=<port for debugging> or –debug-brk=<port for debugging> parameter.

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).

Have a look at the previous post on Node.js development in our blog: “Getting started with Node.js in WebStorm”.

Develop with pleasure!
-JetBrains WebStorm Team

About Ekaterina Prigara

Ekaterina Prigara is WebStorm product marketing manager at JetBrains. She's passionate about new technologies, UX and coffee.
This entry was posted in Tutorials and tagged . Bookmark the permalink.

14 Responses to Running and debugging Node.js application

  1. Chris says:

    It would be nice to cover simultaneously debugging javascript in the browser when running a Node.js app.

    It took me a while to discover I had to edit the JavaScript Debug target’s “Remote URLs of local files” and specify the full URL of the static javascript directory, to get WS7 to honor breakpoints when connected to Firefox.

  2. Pingback: [Webinar Recording] Node.js Development Workflow | JetBrains WebStorm Blog

  3. Pingback: Webinar Recording: Node.js Development Workflow in WebStorm | JetBrains Company Blog

  4. angel says:

    sorry, I follow the steps but I can’t find than the debug stop in my breakpoint, I set the breakpoints, then configure the debugger to point my file and directory, run it and in the console shows than a port is open…what is the next step??…there is some tutorial or video showing how debug??…thanks!

  5. Pingback: Getting Started with Node.js in WebStorm | JetBrains WebStorm Blog

  6. Pingback: Guide to Node.js Development with WebStorm | JetBrains WebStorm Blog

  7. Eric Swann says:

    This demo may no longer be accurate. On windows (x64), I followed the directions and simply got: “Process finished with exit code 0″. No server startup.
    However, the template also comes with a default configuration “bin\www” which did work. It seems that instead of selecting “app.js” for the javascript file to run, you must specify “bin\www” when setting up the config. The demo also doesn’t specify how to set up the default port, which I had to manually add in the app.js: app.set(‘port’, process.env.port || 3000). I see it in the animated image, but there’s no explanation and it’s actually after the lines that state to run the project.

    • Ekaterina Prigara says:

      bin/www configuration was added just recently with WebStorm 8 bug fix update after Express 4 release where the seed project structure was changed. I would update the tutorial.

      • Eric Swann says:

        Cool thanks for the explanation!

      • Maheshwari says:

        I have downloaded evaluation version. And I also get the same “Process finished with exit code 0″ error. I tried to set http://www.js but I am not able to find any such file or setting. Can you please elaborate on this. Probably add the gif file for this update, same as node-rdc.gif?

        Thanks,
        Maheshwari.

        • Ekaterina Prigara says:

          Hello Maheshwari,
          You’ve created a new Express project with Create new project dialog, right? Then you should have a predefined run/debug configuration called www/bin that starts the app.

  8. Lola says:

    Hi,
    I have a problem in WebStorm’s debug Tool with the variables panel. When i am debugging a Node application the “Set value” option is inactive.
    What is the problem?

    Thanks,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">