WebStorm 2017.2 Help

Debugging JavaScript Deployed to a Remote Server

Before you start, install the JetBrains IDE Support Chrome extension. Find more about that and about additional configuration of the debugger in Configuring JavaScript Debugger and JetBrains Chrome Extension.

On this page:

What is a remote web server?

In WebStorm, any server with the document root outside the current project is called remote. This server may be actually running on a physically remote host or on your machine.

For example, if your project is in C:/WebStormProjects/MyProject and the web server document root is C:/XAMPP/htdocs, for WebStorm this web server is remote.

How do I synchronize my application sources on the server with their local copies in my WebStorm project?

To debug an application on a remote web server, you need to have the copies of its sources in a WebStorm project. To synchronize local and remote sources, create a deployment configuration as described in Creating a Remote Server Configuration and Configuring Synchronization with a Web Server.

Debugging an application

  1. Set the breakpoints in the JavaScript code, as required.
  2. Create a debug configuration of the type JavaScript Debug:
    Choose Run | Edit Configuration on the main menu, click the Add New Configuration button add on the toolbar, and select JavaScript Debug from the pop-up list.
  3. In the Run/Debug Configuration: JavaScript Debug dialog box that opens, specify the URL address at which the application is running.

    This URL address should be a concatenation of the Web server root URL and the path to the HTML file relative to the web server document root in accordance with server access configuration, see Configuring Synchronization with a Web Server. Click OK to save the configuration settings.
  4. Choose the newly created configuration in the Select run/debug configuration drop-down list on the tool bar and click the Debug toolbar button debug. The HTML file specified in the run configuration opens in the chosen browser and the Debug tool window appears.
  5. In the Debug tool window, proceed as usual: step through the program, stop and resume the program execution, examine it when suspended, view actual HTML DOM, etc.

Example

Suppose you have a simple application that consists of an index.html file and a MyJavaScript.js file, where index.html references MyJavaScript.js. Let's now deploy our simple application to a local web server, see Using Remote Environments. In this example it is Apache:

ws_quick_start_debug_external_server_0.png

When using a local web server, such as Nginx or Apache, as in our example, or the web server is on a remote host, you need to create a Run/Debug configuration to start the JavaScript debugger. To do that, click the drop-down list at the upper right-hand corner of the WebStorm window and choose Edit Configurations. Alternatively, choose Run | Edit Configurations on the main menu:

ws_quick_start_debug_external_server_1.png
In the Run/Debug Configurations dialog box that opens, click add and choose JavaScript Debug from the list:
ws_quick_start_debug_external_server_2.png
Specify the URL you are running your application at:
ws_quick_start_debug_external_server_3.png
In our example, the local project structure and file structure on the server are the same so no mappings are required.

Now we can start debugging: choose the new run/debug configuration from the drop-down list in the upper right-hand corner of the WebStorm window, and then click debug to the right of the list:

ws_quick_start_debug_external_server_4.png

Configuring mappings

Mappings set correspondence between files on a web server and their local copies.

When do I need mappings?

  1. When your application is deployed and running on a remote web server.
  2. When you have defined several resource root folders in addition to the project root.

In most cases, WebStorm sets path mappings automatically by reusing mappings from the deployment configuration. If your application structure is complicated, additional manual configuration is required.

To configure mappings:

  1. Create a debug configuration of the type JavaScript Debug as described in Debugging an application.
  2. In the Remote URLs of local files area, map the files and folders to URL addresses of files and folders on the server according to the currently used deployment configuration, see Mapping local folders to folders on the server and the URL addresses to access them.

Last modified: 29 November 2017

See Also