IntelliJ IDEA 2019.3 Help

Node.js

Node.js is a lightweight runtime environment for executing JavaScript outside the browser, for example on the server or in the command line. IntelliJ IDEA integrates with Node.js providing assistance in configuring, editing, running, debugging, testing, profiling, and maintaining your applications.

If you need Node.js only as a local runtime for your application or for managing npm packages, running JavaScript linters, build tools, test frameworks, and so on, just install Node.js. If you follow the standard installation procedure, in most cases IntelliJ IDEA detects Node.js itself.

And even if you have no Node.js on your computer, you can install it when creating a new Node.js application in the Create New Project dialogNew Project Wizard, see Creating a new Node.js application below.

If you want to switch among several Node.js installations, they must be configured as local Node.js interpreters. In most cases, IntelliJ IDEA detects Node.js installations, configures them as interpreters automatically, and adds them to the list where you can select the relevant one.

To run a Node.js application remotely, configure it as a remote interpreter. See Node.js with Docker for details.

Switching between Node.js versions

With IntelliJ IDEA, you can have several installations of Node.js and switch between while working on the same project.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Languages and Frameworks | Node.js and NPM.

  2. On the Node.js and NPM page that opens, select the required Node.js installation from the Node Interpreter list.

    If you followed the standard installation procedure, in most cases the required Node.js installation is on the list. If the installation is missing, click the Browse button and configure it as a local interpreter manually.

Using a system Node.js version

With IntelliJ IDEA, you can set the default system node alias as your project’s Node.js version. After that this version will be automatically used by all the tools that require Node.js and in all new run/debug configurations. In particular, this means that you will not have to update the settings for each tool if you install a new Node.js version and make it the default node alias in your system.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Languages and Frameworks | Node.js and NPM.

  2. From the Node interpreter list, select node.

    ws_node_alias.png

  3. Specify this new Node.js interpreter where applicable, for example in your run/debug configurations or settings of specific tools.

Configuring a local Node.js interpreter

You may need to configure Node.js installation as an interpreter manually, for example, if Node.js is installed in a non-default location so IntelliJ IDEA does not detect it automatically.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Languages and Frameworks | Node.js and NPM.

  2. On the Node.js and NPM page, that opens, click the Browse button next to the Node Interpreter list.

  3. In the Node.js Interpreters dialog that opens with a list of all the currently configured interpreters, click the Add button on the toolbar. In the dialog that opens, choose Add Local from the context menu and choose the 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 new interpreter.

  4. In the Package manager field, choose the package manager (npm or Yarn) for 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 Node.js on Windows Subsystem for Linux

IntelliJ IDEA 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, go to Languages and Frameworks | Node.js and NPM.

  2. Click the Browse button next to the Node Interpreter field, in the Node.js Interpreters dialog that opens, click the Add button, and then select 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

Creating a Node.js application

If you have no application yet, you can generate a IntelliJ IDEA project with Node.js-specific structure from a template or create an empty IntelliJ IDEA project and configure Node.js in it as described in Starting with an existing Node.js application below.

To create a new Node.js application

  1. Select File | New | Project from the main menu or click the New Project button on the Welcome screen.

  2. In the New Project dialog, select Node.js and NPM in the left-hand pane.

  3. In the right-hand pane, choose Node.js Express App and click Next.

  4. On the second page of the wizard, specify the project folder, the Node.js interpreter, the package manager (npm or Yarn, see npm and Yarn for details).

    For Node.js Express app, specify the version of express-generator and select the template language and the Style Sheet language to use.

  5. When you click Finish, IntelliJ IDEA downloads the necessary dependencies and enables code completion for them as well as for the Node.js core APIs, see Configuring node_modules library and Configuring Node.js Core library for details.

    For Node.js Express, IntelliJ IDEA creates a run/debug configuration of the type Node.js with default settings and generates a basic Node.js Express-specific directory structure.

    For Node.js, IntelliJ IDEA just runs the npm init command to generate a package.json file.

To create an empty IntelliJ IDEA project

  1. Select File | New | Project from the main menu or click the New Project button on the Welcome screen.

  2. In the New Project dialog, select Static Web in the left-hand pane.

  3. In the right-hand pane, again select Static Web and click Next.

  4. On the second page of the wizard, specify the project folder and name and click Finish.

Starting with an existing Node.js application

If you are going to continue developing an existing Node.js application, open it in IntelliJ IDEA, configure Node.js in it, and download the required dependencies.

To open the application sources that are already on your machine

  • Click Open on the Welcome screen or select File | Open from the main menu. In the dialog that opens, select the folder where your sources are stored.

To check out the application sources from your version control

  1. Click Get from Version Control on the Welcome screen or select VCS | Get from Version Control from the main menu.

  2. In the invoked dialog, select your version control system from the list and specify the repository to check out the application sources from.

To configure Node.js in a project

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Languages and Frameworks | Node.js and NPM.

  2. In the Node Interpreter field, specify the default Node.js interpreter for the current project. IntelliJ IDEA 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 ESLint.

    Select a configured interpreter from the list or click the Browse button and configure a new one in the dialog that opens as described in Configuring a local Node.js interpreter. If you select 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, IntelliJ IDEA provides code completion, reference resolution, validation, and debugging capabilities for fs, path, http, and other parts of Node.js that are compiled into the Node.js binary.

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

  4. If you need code completion for Node.js APIs only in some parts of your project, you can configure that using the Manage scopes link. In the Usage dialog that opens, click the relevant directories and for each of them select the configured Node.js Core library from the list. Learn more from Configuring the scope of a library.

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

  • In the embedded Terminal (Alt+F12), type:

    npm install

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

Last modified: 9 December 2019