A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.jetbrains.com/webstorm/help/node-with-docker.html below:

Node.js with Docker | WebStorm Documentation

Node.js with Docker

With Docker, you can quickly bootstrap your Node.js application to run, debug, and profile it from WebStorm. The IDE will take care of the initial configuration by automatically creating a new Dockerfile, building and running an image, syncing your source code, and installing npm dependencies in the container.

You can find some examples at Quick Tour of WebStorm and Docker.

Before you start
  1. Make sure the JavaScript Debugger, Node.js, Node.js Remote Interpreter, and Docker required plugins are enabled on the Settings | Plugins page, tab Installed. For more information, refer to Managing plugins.

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

Configure a Node.js interpreter in Docker

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 Settings dialog or later, when you create or edit a Node.js run/debug configuration for running or debugging your application in Docker.

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. 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.

Create a remote Node.js interpreter
  1. Open the Settings dialog (Ctrl+Alt+S) and go to .

  2. Click next to the Node interpreter field.

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

  4. In the Configure Node.js Remote Interpreter dialog that opens, select Docker.

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

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

  6. From the Image name list, select the image to use.

    The Node.js executable is detected automatically and is shown in the Node.js interpreter path field.

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

  8. To set the newly configured interpreter as project default, select it in the list and click OK to return to the Node.js dialog.

    WebStorm 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 project Node.js interpreter and package manager.

Specify the default project Node.js interpreter and package manager

WebStorm 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 Settings dialog (Ctrl+Alt+S) and go to .

  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. WebStorm detects its location automatically.

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

npm, pnpm, and yarn with Docker

With WebStorm, you can manage project dependencies and run scripts in a Docker container just in the same way as you do with local projects.

  1. Make sure you have configured a remote Node.js interpreter in Docker.

  2. Specify the default project Node.js interpreter and package manager

  3. Manage your project dependencies.

    Learn more from Install and update packages and Edit package.json.

  4. Run and debug scripts

Create a Node.js run configuration
  1. Go to . In the Edit Configuration dialog that opens, click on the toolbar and select Node.js from the context menu. The Run/Debug Configuration: Node.js 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).

  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 in a Docker environment.

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

  5. Check the port and volume bindings values in the Docker container settings field.

Run your application
  1. Create a Node.js run/debug configuration as described above.

  2. From the Select run/debug configuration list on the toolbar, select the newly created Node.js configuration.

  3. Click to the Select run/debug configuration list.

Check the application output

To make sure the application works as expected, you can run a HTTP request from the WebStorm built-in HTTP Client.

  1. Create a HTTP Request file.

  2. Write the following request:

    GET http://<host IP>:<container port>/

    For example:

    GET http://127.0.0.1:3010/

  3. Click in the gutter and click next to Run http://<host IP>:<container port>/.

    The application output is shown in a separate tab of the Run tool window.

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 next to the list.

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

Test your application

With WebStorm, you can run Mocha and Jest tests inside a Docker container just in the same way as you do it locally. For more information, refer to Mocha and Jest.

  1. Make sure a relevant remote Node.js interpreter in Docker is configured and selected as default for your project. Also make sure the package manager associated with this remote interpreter is set as project default. For more information, refer to Configure a Node.js interpreter in Docker and npm, pnpm, and yarn with Docker.

  2. Open your package.json and make sure the required test framework is listed in the devDependencies section:

    { "name": "node-express", "version": "0.0.0", "private": true, "dependencies": { "cookie-parser": "~1.4.4", "debug": "~2.6.9", "express": "~4.16.1", "http-errors": "~1.6.3", "morgan": "~1.9.1", "pug": "^3.0.2" }, "devDependencies": { "chai": "^4.3.4", "concurrently": "^6.3.0", "eslint": "^8.1.0", "http-server": "^14.0.0", "jest": "^27.3.1", "mocha": "^9.1.3", "nyc": "^15.1.0" } }

  3. Right-click anywhere in the editor and select Run '<package manager> install' from the context menu.

  4. Create tests according to the instructions from the Mocha official website or Jest official website.

  5. Run and debug single tests right from the editor or create a run/debug configuration to launch some or all of your tests as described in Running Mocha tests, Debugging Mocha tests, Running Jest tests, and Debugging Jest tests.

ESLint with Docker

With WebStorm, you can run ESLint against your code inside a Docker container just in the same way as you do it locally. For more information, refer to JavaScript linters and ESLint.

  1. Make sure a relevant remote Node.js interpreter in Docker is configured and selected as default for your project. Also make sure the package manager associated with this remote interpreter is set as project default. For more information, refer to Configure a Node.js interpreter in Docker and npm, pnpm, and yarn with Docker.

  2. Open your package.json and make sure ESLint is listed in the devDependencies section:

    { "name": "node-express", "version": "0.0.0", "private": true, "dependencies": { "cookie-parser": "~1.4.4", "debug": "~2.6.9", "express": "~4.16.1", "http-errors": "~1.6.3", "morgan": "~1.9.1", "pug": "^3.0.2" }, "devDependencies": { "eslint": "^8.1.0" } }

  3. Right-click anywhere in the editor and select Run '<package manager> install' from the context menu.

  4. After that, ESLint works in the same way as when you work with your code locally. View descriptions of detected discrepancies right in the editor or in the Problems tool window and apply suggested quick-fixes. For more information, refer to JavaScript linters and ESLint.

Last modified: 11 October 2024


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4