PhpStorm 2018.2 Help

Node.js

Node.js is a lightweight runtime environment for executing JavaScript on the server side. PhpStorm integrates with Node.js providing assistance in configuring, editing, running, debugging, testing, profiling, and maintaining your applications.

If you need Node.js only for managing npm packages or running JavaScript linters, build tools, test frameworks, etc., just install Node.js. If you follow the standard installation procedure, in most cases PhpStorm detects Node.js itself.

To use Node.js as a runtime for your application, you need to configure it as a local or remote interpreter.

Configuring a local Node.js interpreter

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click Node.js and NPM under Languages and Frameworks.

  2. On the Node.js and NPM page, that opens, 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 icons general add svg 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 Package manager field, choose the package manager (npm or Yarn) to use in the current project, see Configuring a package manager for a project for details.

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 PhpStorm, 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 PhpStorm 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), click 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.

    ws_node_alias.png

  3. Specify this new Node.js interpreter where applicable, e.g. in you run/debug configurations or settings of specific tools.

Using Node.js on Windows Subsystem for Linux

PhpStorm lets you run and debug Node.js applications using Node.js on Windows Subsystem for Linux. You can choose Node.js on WSL as the default interpreter for the current project or you can configure and use this node version in a Node.js Run/Debug configuration.

To configure Node.js on WSL as the default project node interpreter

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click Node.js and NPM under Languages and Frameworks. The Node.js and NPM page opens.

  2. Click browseButton next to the Node Interpreter field, in the Node.js Interpreters dialog that opens, click icons general add svg, and then choose Add WSL from the list.

    Configuring Node.js on WSL as the default project node interpreter

  3. In the Add WSL Node Interpreter dialog that opens, select the Linux distribution you’re using and specify the path to Node.js.

    Specifying the Linus distribution and the path to Node.js

Quick start with a Node.js application

Here we will use a simple Express application as an example.

To create an application

  1. Choose File | New | Project on the main menu or click Create New Project on the Welcome screen. The Create New Project Dialog opens.

  2. In the left-hand pane, choose Node.js Express App.

  3. In the right-hand pane, specify the project folder, the Node.js interpreter, and the version of express-generator to use. In the Options area, choose the template language and the Style Sheet language to use.

  4. When you click Create, PhpStorm generates a Node.js Express-specific project with all the required configuration files.

To download the project dependencies, do one of the following:

  • Open the embedded Terminal (View | Tool Windows | Terminal or Alt+F12) and type npm install at the command prompt.

  • Choose Run 'npm install' on the context menu of the package.json file in your project root.

To configure Node.js in a project

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click Node.js and NPM under Languages and Frameworks. The Node.js and NPM page opens.

  2. In the Node Interpreter field, specify the default Node.js interpreter for the current project. PhpStorm will automatically use it every time you select the Project alias from Node Interpreter lists when creating run/debug configurations or configuring Node.js-dependent tools, for example, Prettier or Yeoman.

    Choose the interpreter from the drop-down list or from the dialog that opens when you click browseButton. If you choose node, the system Node.js version is used.

  3. Select the Coding assistance for Node.js checkbox to configure the Node.js Core module sources as a JavaScript library and associate it with your project. As a result, PhpStorm provides code completion, reference resolution, validation, and debugging capabilities for fs, path, http, and other core modules that are compiled into the Node.js binary.

    When the configuration is completed, PhpStorm displays information about the currently configured version.

  4. Optionally, configure the scope in which the Node.js Core sources are treated as libraries:
    1. Click Manage scopes. The Usage Scope dialog opens.

    2. Click the relevant directories, and for each of them select the newly configured Node.js Core library from the list.

Last modified: 21 November 2018

See Also