PyCharm 2017.3 Help

Configuring Node.js Interpreters

This feature is only supported in the Professional edition.

With PyCharm, you can use local and remote Node.js interpreters. The term local Node.js interpreter denotes a Node.js installation on your computer. The term remote Node.js interpreter denotes a Node.js installation on a remote host or in a virtual environment set up in a Vagrant instance. Local interpreters are configured on the Node.js and NPM page as described below.

You can use a remote interpreter in four ways:

  • Through SSH credentials to access the host where the Node.js interpreter is installed.
  • Through access to the corresponding Vagrant instance.
  • According to a Server Access Configuration. This approach is also helpful if you are going to synchronize your project sources with the Web server on the target remote host.
  • Through access to a Docker Container with Node.js.
Remote interpreters are configured in the Configure Node.js Remote Interpreter Dialog dialog that opens only from the Run/Debug Configuration: Node.js dialog. See Configuring remote Node.js interpreters for details.

Configuring a local Node.js interpreter

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), choose Node.js and NPM under Languages and Frameworks. The Node.js and NPM page opens.
  2. Click the browseButton next to the Node Interpreter drop-down list.
  3. In the Node.js Interpreters Dialog that opens with a list of all the currently configured interpreters, click new on the toolbar. In the dialog box that opens, choose Add Local on the context menu and choose the local installation of Node.js, then click OK. You return to the Node.js Interpreters Dialog where the Node interpreter read-only field shows the path to the chosen interpreter.
  4. In the Npm package field, specify the Node package manager (npm) associated with the selected interpreter. Choose the relevant npm from the drop-down list or click browseButton next to it and in the dialog box that opens choose the location of the npm to use.

    Alternatively, you can specify the path to the Yarn package manager if you want to use it instead of npm.

    The field is available only if the selected interpreter is of the type local.

When you click OK, you return to the Node.js and NPM page where the Node interpreter field shows the new interpreter.

Using a system Node.js version

With PyCharm, you can set the default system node alias as your project’s Node.js version. This means that if you install a new node version and make it the default in your system, all the tools and run configurations in PyCharm where this system alias is specified in the Node.js interpreter field will use this newer version.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), choose Node.js and NPM under Languages and Frameworks. The Node.js and NPM page opens.
  2. From the Node interpreter drop-down list, choose node.
  3. Specify this new Node.js interpreter where applicable, e.g. in you run/debug configurations or settings of specific tools.
ws_node_alias.png

Configuring a remote Node.js interpreter on a host accessible through SSH connection

Before you start:

  1. Configure access to an ssh server on the target remote host and make sure this server is running.
  2. Make sure the Node.js Remote Interpreter repository plugin is installed and enabled. The plugin is not bundled with PyCharm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

To configure a Node.js interpreter using SSH credentials:

  1. On the main menu, choose Run | Edit Configurations. 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. In the Run/Debug Configuration: Node.js dialog that opens, click browseButton next to the Node interpreter field.
  2. In the Node.js Interpreters Dialog that opens with a list of all the currently configured interpreters, click new on the toolbar. In the dialog box that opens, choose Add Remote on the context menu.
  3. In the Configure Node.js Remote Interpreter Dialog that opens, choose the SSH Credentials method.
  4. Specify the name of the remote host and the port which the SSH server listens to. The default port number is 22.
  5. Specify your credentials to access the remote host in accordance with the credentials received during the registration on the server. Type your user name and choose the authentication method:
    • To access the host through a password, choose Password from the Auth type drop-down list, specify the password, and select the Save password checkbox to have PyCharm remember it.
    • To use SSH authentication via a key pair, choose Key pair (OpenSSH or PuTTY). To apply this authentication method, you need to have your private key on the client machine and your public key on the remote server you connect to. PyCharm supports private keys generated using the OpenSSH utility.

      Specify the path to the file where your private key is stored and type the passphrase (if any) in the corresponding text boxes. To have PyCharm remember the passphrase, select the Save passphrase checkbox.

    • If your SSH keys are managed by a credentials helper application (for example, Pageant on Windows or ssh-agent on Mac and Linux), choose Authentication agent (ssh-agent or Pageant).
  6. Specify the location of the Node.js executable file in accordance with the configuration of the selected remote development environment. By default PyCharm suggests the /usr/bin/node folder for remote hosts and Vagrant instances and node for Docker containers. To specify a different folder, click the Browse button browseButton and choose the relevant folder in the dialog box that opens. Note that the Node.js home directory must be open for edit.
  7. When you click OK, PyCharm checks whether the Node.js executable is actually stored in the specified folder.
    • If no Node.js executable is found, PyCharm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
    • If the Node.js executable is found, you return to the Node.js Interpreters where the installation folder and the detected version of the Node.js interpreter are displayed.

Configuring a remote Node.js interpreter in a Vagrant environment instance

Before you start:

  1. Make sure that Vagrant and Oracle's VirtualBox are downloaded, installed, and configured on your computer as described in Vagrant: Working with Reproducible Development Environments.
  2. Make sure the Vagrant and Node.js Remote Interpreter plugins are installed and enabled. The plugins are not bundled with PyCharm, but they can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins. Once enabled, the plugins are available at the IDE level, that is, you can use them in all your PyCharm projects.
  3. Make sure the Node.js Remote Interpreter repository plugin is installed and enabled. The plugin is not bundled with PyCharm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
  4. Make sure that the parent folders of the following executable files are added to the system PATH variable:
    • vagrant.bat or vagrant from your Vagrant installation. This should be done automatically by the Vagrant installer.
    • VBoxManage.exe or VBoxManage from your Oracle's VirtualBox installation.
  5. Configure the Node.js development environment in the Vagrant instance to be used. Learn more about using Vagrant with PyCharm in Vagrant: Working with Reproducible Development Environments.

To configure a Node.js Interpreter in a Vagrant instance

  1. On the main menu, choose Run | Edit Configurations. 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. In the Run/Debug Configuration: Node.js dialog that opens, click browseButton next to the Node interpreter field.
  2. In the Node.js Interpreters Dialog that opens with a list of all the currently configured interpreters, click new on the toolbar. In the dialog box that opens, choose Add Remote on the context menu.
  3. In the Configure Node.js Remote Interpreter Dialog that opens, choose the Vagrant method.
  4. Specify the Vagrant instance folder which points at the environment you are going to use. Technically, it is the folder where the VagrantFile configuration file for the desired environment is located. Based on this setting, PyCharm detects the Vagrant host and shows it as a link in the Vagrant Host URL read-only field.
  5. Specify the location of the Node.js executable file in accordance with the configuration of the selected remote development environment. By default PyCharm suggests the /usr/bin/node folder for remote hosts and Vagrant instances and node for Docker containers. To specify a different folder, click the Browse button browseButton and choose the relevant folder in the dialog box that opens. Note that the Node.js home directory must be open for edit.
  6. When you click OK, PyCharm checks whether the Node.js executable is actually stored in the specified folder.
    • If no Node.js executable is found, PyCharm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
    • If the Node.js executable is found, you return to the Node.js Interpreters where the installation folder and the detected version of the Node.js interpreter are displayed.

Configuring a remote Node.js interpreter on a remote host accessible through SFTP

Before you start:

  1. Make sure a ssh server is running on the target remote host and you have configured access to it.
  2. Make sure the Remote Hosts Access plugin is enabled. The plugin is activated by default. If the plugin is disabled, enable it on the Plugins settings page as described in Enabling and Disabling Plugins.
  3. Make sure you have at least one PyCharm-wide server access configuration of the SFTP type to establish access to the target host. To make a configuration available in all PyCharm projects, clear the Visible only for this project checkbox in the Connection Tab. See Creating a Remote Server Configuration for details.

To configure a remote Node.js interpreter based on an SFTP server access configuration

  1. On the main menu, choose Run | Edit Configurations. 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. In the Run/Debug Configuration: Node.js dialog that opens, click browseButton next to the Node interpreter field.
  2. In the Node.js Interpreters Dialog that opens with a list of all the currently configured interpreters, click new on the toolbar. In the dialog box that opens, choose Add Remote on the context menu.
  3. In the Configure Node.js Remote Interpreter Dialog that opens, choose the Deployment Configuration method.
  4. From the Deployment Configuration drop-down list, choose the server access configuration of the SFTP type according to which you want PyCharm to connect to the target host. If the settings specified in the chosen configuration ensure successful connection, PyCharm displays the URL address of the target host as a link in the Deployment Host URL field.

    To use an interpreter configuration, you need path mappings that set correspondence between the project folders, the folders on the server to copy project files to, and the URL addresses to access the copied data on the server. By default, PyCharm retrieves path mappings from the chosen server access (deployment) configuration. If the configuration does not contain path mappings, PyCharm displays the corresponding error message.

    To fix the problem, open the Deployment page under the Build, Execution, Deployment node, select the relevant server access configuration, switch to the Mappings tab, and map the local folders to the folders on the server as described in Creating a Remote Server Configuration section.

  5. Specify the location of the Node.js executable file in accordance with the configuration of the selected remote development environment. By default PyCharm suggests the /usr/bin/node folder for remote hosts and Vagrant instances and node for Docker containers. To specify a different folder, click the Browse button browseButton and choose the relevant folder in the dialog box that opens. Note that the Node.js home directory must be open for edit.
  6. When you click OK, PyCharm checks whether the Node.js executable is actually stored in the specified folder.
    • If no Node.js executable is found, PyCharm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
    • If the Node.js executable is found, you return to the Node.js Interpreters where the installation folder and the detected version of the Node.js interpreter are displayed.

Configuring a remote Node.js interpreter in a Docker container

You can quickly bootstrap your Node.js application with Docker, PyCharm will take care of the initial configuration by automatically creating a new Dockerfile, keeping your source code up-to-date and installing npm dependencies in the container. Configuring a Node.js environment running in a Docker container as a Node.js remote interpreter lets you run, debug, and profile your Node.js application from PyCharm.

Before you start:

  1. Make sure the Node.js, Node.js Remote Interpreter, and Docker Integration plugins are enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Plugins settings page as described in Enabling and Disabling Plugins.
  2. Download, install, and configure Docker as described in Docker.

To configure a remote Node.js interpreter in a Docker container:

  1. On the main menu, choose Run | Edit Configurations. 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. In the Run/Debug Configuration: Node.js dialog that opens, click browseButton next to the Node interpreter field.
  2. In the Node.js Interpreters Dialog that opens with a list of all the currently configured interpreters, click new on the toolbar. In the dialog box that opens, choose Add Remote on the context menu.
  3. In the Configure Node.js Remote Interpreter Dialog that opens, choose the Docker method.
  4. In the Server field, specify the Docker configuration to use, see Working with Docker: Process overview. Choose a configuration from the drop-down list or click browseButton next to it and create a new configuration in the Docker dialog box that opens.
  5. In the Image name field, specify the base Docker image to use. Choose one of the previously downloaded or your custom images from the drop-down list or type the image name manually, for example, node:argon or mhart/alpine-node. When you later launch the run configuration, Docker will search for the specified image on your machine. If the search fails, the image will be downloaded from the image repository specified on the Registry page.
  6. The Node.js interpreter path field shows the location of the default Node.js interpreter from the specified image.
  7. When you click OK, PyCharm closes the Configure Node.js Remote Interpreter Dialog and brings you to the Node.js Interpreters Dialog where the new interpreter configuration is added to the list. Click OK to return to the run configuration.

Configuring mappings

When you debug an application with a remote Node.js interpreter, the debugger tells PyCharm the name of the currently processed file and the number of the line to be processed. PyCharm opens the local copy of this file and indicates the line with the provided number. This behaviour is enabled by specifying correspondence between files and folders on the server and their local copies. This correspondence is called mapping, it is set in the debug configuration.

If you use an interpreter accessible through SFTP connection or located on a Vagrant instance, the mappings are automatically retrieved from the corresponding deployment configuration or Vagrantfile. To specify additional mappings:

  1. On the main menu, choose Run | Edit Configurations. 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.
  2. In the Run/Debug Configuration: Node.js dialog that opens, choose the required remote interpreter from the Node interpreter drop-down list.
  3. Click browseButton next to the Path Mappings field.
  4. The Edit Project Path Mappings Dialog that opens, shows the path mappings retrieved from the deployment configuration or Vagrantfile. These mappings are read-only.
    • To add a custom mapping, click new and specify the path in the project and the corresponding path on the remote runtime environment in the Local Path and Remote Path fields respectively. Type the paths manually or click browseButton and select the relevant files or folders in the dialog box that opens.
    • To remove a custom mapping, select it in the list and click delete.
Last modified: 28 March 2018

See Also