CLion 2016.1 Help

Running and Debugging Node.js

On this page:

Before You Start

Install and enable the NodeJS plugin. The plugin is not bundled with CLion, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

Local and Remote Modes of Running or Debugging Node.js Applications

Running a Node.js application in CLion is supported only in the local mode. This means that CLion itself starts the Node.js engine and the target application according to a run configuration and gets full control over the session.

Debugging can be performed in two modes:

  • Locally, with the Node.js engine started from CLion.
  • Remotely, when CLion connects to an already running Node.js application. This approach gives you the possibility to re-start a debugging session without re-starting the Node.js server.
In either case, the debugging session is initiated through a debug configuration

You can also configure the behaviour of the browser and enable debugging the client-side code of the application. This functionality is provided through a JavaScript Debug run configuration, so technically, CLion creates separate run configurations for the server-side and the client-side code, but you specify all your settings in one dedicated NodeJS run configuration.

Running a Node.js Application

  1. Create a Node.js run configuration.
  2. To launch the application, select the run configuration from the list on the main tool bar and then choose Run | Run <configuration name> on the main menu or click the Run toolbar button run.png. The Run tool window opens.
  3. Open the browser of your choice and open the page with the URL address generated through the server.listen function based on the port and host parameters. The page shows the result of executing your Node.js application.

Debugging a Node.js Application Locally

  1. Set the breakpoints in the Node.js code, where necessary. At least one breakpoint is necessary otherwise the program will be just executed. If you want the debugging tool to stop at the first line of your code, set a breakpoint at the first line.
  2. Create a Node.js run/debug configuration.
  3. To start a debugging session, select the required debug configuration from the list on the main tool bar and then choose Run | Debug <configuration name> on the main menu or click the Debug toolbar button debug.png.
  4. Open the browser of your choice and open the starting page of your application. Control over the debugging session returns to CLion.
  5. Switch to CLion, where the controls of the Debug tool window are now enabled. Proceed with the debugging session step through the breakpoints, switch between frames, change values on-the-fly, examine a suspended program, evaluate expressions, and set watches.

See Also

Last modified: 20 July 2016