AppCode 2023.1 Help

Node.js with Docker Compose

Docker Compose is used to run multi-container applications. For example, you can run a web server, a backend database, and your application code as separate services. Each service can be scaled by adding more containers if necessary. This enables you to perform efficient development and testing in a dynamic environment, similar to production.

Before you start

  1. Make sure the JavaScript and TypeScript, JavaScript Debugger, and Docker required plugins are enabled on the Settings | Plugins page, tab Installed, see Managing plugins for details.

  2. Install the Node.js and Node.js Remote Interpreter plugins on the Settings | Plugins page, tab Marketplace, as described in Installing plugins from JetBrains repository.

  3. Install the Node.js and Node.js Remote Interpreter plugins on the Settings | Plugins page, tab Marketplace, as described in Installing plugins from JetBrains repository.

  4. Download, install, and configure Docker as described in Docker

Configure a Node.js interpreter with Docker Compose

Node.js interpreters in Docker are configured in the Configure Node.js Remote Interpreter dialog. You can open this dialog from the Node.js page of the Preferences 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 Preferences dialog. In this case you can set the interpreter and the associated package manager as default for your project. As a result, you can not only run and debug your app with configured Node.js interpreter in Docker but also manage your project dependencies, run tests, and lint your code. See npm, pnpm, and yarn with Docker, Test your application, and ESLint with Docker below.

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 Preferences dialog (Ctrl+Alt+S) and go to Languages & Frameworks | Node.js.

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

  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 in Docker container: Add Remote
  4. In the Configure Node.js Remote Interpreter dialog that opens, select Docker Compose.

  5. From the Server list, select the Docker configuration to use.

    Configure a Node.js interpreter via Docker Compose: select the Docker Server

    Alternatively, click New next to the field and configure a Docker server as described in Enable Docker support.

  6. In the Configuration files field, specify the docker-compose configuration files to use. Press Browse and create a list of configuration files in the Docker Compose Configuration Files dialog, that opens.

    Configure a Node.js interpreter via Docker Compose: configuration files
  7. From the Service list, select the service to use:

    Configure Node.js interpreter via Docker Compose: select service
  8. 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 in Docker added to the list
  9. To set the newly configured interpreter as project default, select it in the list and click OK to return to the Node.js dialog.

    Settings: newly configured remote Node.js interpreter selected as default

    AppCode 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. Learn more from Specify the default Node.js interpreter and package manager in a project.

Specify the default Node.js interpreter and package manager in a project

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

The default project package manager is used automatically for managing dependencies, for example, when you run <package manager> install from a package.json file or install third-party tools, such as ESLint, Prettier, and so on.

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

  2. From the Node interpreter list, select the configuration to use by default in the current project.

  3. From the Package manager list, select the alias associated with the package manager to use. AppCode detects its location automatically.

    Settings: newly configured remote Node.js interpreter selected as default

    Alternatively, specify the location of the required package manager manually.

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

    • The default location for pnpm depends on the installation method:

      1. /usr/local/lib/node_modules/pnpm for installation through npm.

      2. /usr/local/pnpm-global/<version>/node_modules/pnpm for installation through curl (curl -f https://get.pnpm.io/<version>.js | node - add --global pnpm).

      Learn more from the pnpm official website.

    • The default location for yarn is /opt/yarn-<version>5, for example, /opt/yarn-v1.22.5.

    Configure Node.js interpreter in Docker container: set as default project interpreter

Create a Node.js run/debug configuration

  1. From the main menu, select 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: Node.js dialog opens.

  2. In the JavaScript 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 via Docker Compose.

    Node.js with Docker: run/debug configuration, select interpreter

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

    Node.js with Docker: run/debug configuration, configure interpreter, select Add Remote
  5. In the Docker Compose area, specify the commands and options to be passed to Docker Compose. Accept the default settings or click the Expand button and specify custom ones, for example, custom Docker Compose flags, like --rm or --service-ports. Learn more from the Docker official website

    Check the Command Preview.

    Docker Compose area preview
Last modified: 17 March 2023