PhpStorm 6.0.1 Web Help

Running and debugging of Node.js applications in PhpStorm is supported through the Node.js plugin.

Running a Node.js application in PhpStorm is supported only in the local mode. This means that PhpStorm 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:

In either case, the debugging session is initiated through a debug configuration

In this section:

To run 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.
  3. In the Run tool window, that opens, copy the URL address at which the application is running. The URL address is specified in the following information message:
    Server running at http://<host>:<port>/
                    
  4. Open the browser of your choice and open the page with the copied URL address. The page shows the result of executing your Node.js application.
To debug a Node.js application locally
  1. Set the breakpoints in the Node.js code, where necessary.
  2. Create a Node.js run/debug configuration.
  3. To start a debugging session, select the 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. In the Console tab of the Debug tool window, that opens, copy the URL address at which the application is running. The URL address is specified in the following information message:
    Server running at http://<host>:<port>/
                    
  5. Open the browser of your choice and open the page with the copied URL address. Control over the debugging session returns to PhpStorm.
  6. Switch to PhpStorm, 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. :
To debug a running Node.js application

The procedure falls into two parts: first we start an application as usual and then connect to it with the debugger.

  1. Set the breakpoints in the Node.js code, where necessary.
  2. Create a Node.js run configuration with the following option in the Node parameters text box: --debug==<port for connect to debugger remotely>
  3. Run the application with the created configuration.
  4. Create a Node.js Remote Debug configuration: in the Debug port text box, type the port number specified in the currently running Node.js configuration.
  5. With the application still running, launch the Node.js Remote Debug configuration (select the configuration in the list and click the Debug toolbar button debug.png).
  6. In the Run tool window, copy the URL address of the server and open the corresponding page in the browser. Control over the debugging session returns to PhpStorm.
  7. Switch to PhpStorm. In the Debug tool window, step through the breakpoints, switch between frames, change values on-the-fly, examine a suspended program, evaluate expressions, and set watches.
To create a Node.js run/debug configuration
  1. On the main menu, choose Run | Edit Configurations.
  2. In the Edit Configuration dialog box, that opens, click the Add New Configuration toolbar button add.png, and choose Node.js on the context menu.
  3. In the Run/Debug Configuration: Node.js dialog box, that opens, specify the following:
    • The name of the configuration.
    • The path to the Node.js executable file.

      Note

      This field is already filled in if you have appointed a default installation.

    • To enable remote debugging of the application, specify the following option in the Node parameters text box: --debug==<port for connect to debugger remotely>
    • The location of the file to start running the Node.js application.
    • If the file to run references any other files, specify their location in the Working directory field.
    • If applicable, in the Application parameters text box, specify the arguments to be passed to the application on start through the process.argv array.
  4. Click OK, when ready.
To create a Node.js Remote Debug configuration
  1. On the main menu, choose Run | Edit Configurations.
  2. In the Edit Configuration dialog box, that opens, click the Add New Configuration toolbar button add.png, and choose Node.js Remote Debug on the context menu.
  3. In the Run/Debug Configuration: Node.js Remote Debug dialog box, that opens, specify the following:
    • The name of the configuration.
    • The host where the target application is running.
    • The port to connect to. Copy the port number from the information message in the Run tool window that controls the running application.
  4. Click OK, when ready.

See Also

Concepts:

Procedures:

Reference:

Web Resources: