PhpStorm 2024.3 Help

Node.js via SSH

Before you start

  1. Make sure the JavaScript and TypeScript, JavaScript Debugger, Node.js, Node.js Remote Interpreter, and FTP/SFTP/WebDAV Connectivity required plugins are enabled on the Settings | Plugins page, tab Installed. For more information, refer to Managing plugins.

  2. Configure access to an SSH server on the target remote host as described in Create SSH configurations and make sure this server is running.

  3. Make sure your project sources are on the target remote host. This can be done in the following two ways:

    • Upload your project sources to the target remote host as described in Upload and download files.

    • Enable a network share on your local machine and mount your project folder in the target directory on the remote host.

      The way you share files and folders depends on the operating system you are using. For more information, refer to your OS instructions.

Configure a Node.js interpreter on a remote host accessible via SSH

Node.js interpreters via SSH are configured in the Configure Node.js Remote Interpreter dialog. You can open this dialog from the Node.js page of the Settings dialog or later, when you create or edit a Node.js run/debug configuration for running or debugging your application.

The recommended way is to configure a remote Node.js interpreter in the Settings dialog. In this case you can set the interpreter and the associated package manager as default for your project.

A remote Node.js interpreter that you configure right in the Node.js run/debug configuration can be used only with this run/debug configuration.

  1. Open the Settings dialog (Ctrl+Alt+S) and go to Languages & Frameworks | Node.js.

  2. Click the Browse button next to the Node interpreter field.

    Add interpreter - Browse button
  3. In the Node.js Interpreters dialog with a list of all the currently configured interpreters, click the Add button on the toolbar and select Add Remote from the context menu .

    Configure Node.js interpreter via SSH: Add Remote
  4. In the Configure Node.js Remote Interpreter dialog that opens, select SSH.

  5. Select an SSH configuration to use.

    Configure remote Node.js interpreter via SSH: select SSH configuration

    Alternatively, click the Browse button and create a new SSH configuration as described in Create SSH configurations.

  6. Click OK to return to the Node.js Interpreters dialog where the new interpreter is added to the list.

    Remote Interpreters dialog: the new Node.js interpreter via SSH added to the list
  7. To set the newly configured interpreter as project default, select it in the list and click OK to return to the Node.js dialog.

    PhpStorm automatically uses this interpreter every time you select the Project alias from Node Interpreter lists, for example, when creating run/debug configurations.

    To use the package manager associated with the new interpreter for managing your project dependencies, set this package manager as default in your project. To do that, specify the location of the package manager in the Package manager field.

    The default location for npm executable is /usr/local/lib/node_modules/npm.

    Configure Node.js interpreter via SSH: set as default project interpreter

Create a Node.js run/debug configuration

  1. Go to Run | Edit Configurations. In the Edit Configuration dialog that opens, click the Add New Configuration button on the toolbar and select Node.js from the context menu. The Run/Debug Configuration dialog opens.

  2. In the File field, specify the path to the main file of the application that starts it (for example, bin/www for Express applications).

    Node.js run/debug configuration: JavaScript file specified
  3. If necessary, specify some optional settings as described in Running and debugging Node.js applications.

  4. From the Node interpreter list, select the relevant remote Node.js interpreter accessible via SSH.

    Create Node.js run configuration: select remote Node.js via SSH interpreter

    Alternatively, Click the Browse button next to the Node interpreter field and configure a remote Node.js interpreter as described above.

  5. Map the local folders with the folders on the remote host.

    1. Click the Browse button next to the Path mappings field or press Shift+Enter.

    2. In the Edit Project Path Mappings dialog that opens, click the Add button on the toolbar.

      Create Node.js run configuration: add mapping
    3. Specify the paths to the local folders and the corresponding folders on the remote host. For example, you can map the project folder to /home/opc.

      Create Node.js run configuration: mapping added
    4. When you click OK, you return to the Run/Debug Configurations dialog where the new mapping is shown in the Path mappings field.

      Create Node.js run configuration: added mapping shown

Run your application

  • From the Run/Debug Configurations widget list on the toolbar, select the newly created Node.js configuration and click the Run button next to it.

  • Alternatively, create a Node.js run/debug configuration as described above or modify an existing one and click Run in the dialog.

Debug your application

  1. Set the breakpoints in the Node.js code as necessary.

  2. Create a Node.js configuration as described above, select it from the Select run/debug configuration list on the toolbar, and click the Debug button next to the list.

  3. Proceed as when starting the debugger together with a Node.js application locally.

Last modified: 11 October 2024