Debugging of node. js in webstorm 11

Source: Internet
Author: User

Debugging of node. js in webstorm 11

Recently, I am looking at node. js to briefly record how to run and debug js Code in webstorm 11.
1.There are many online tutorials for installing node. js. If you do not need to modify the default path of the module installation, do not install other modules first.
1.1After the installation is complete, run the command to check that 4.4.2 is used.

1.2Modify the default path of npm Configuration

If the default position of the npm download module is not modified, the default installation path is npm and npm-cache under C: \ Users \ Administrator \ AppData \ Roaming, all modules are installed here

Method 1:

Find the node installation path, go to node_modules-> npm, for example, D: \ install \ node \ node_modules \ npm, find the npmrc file, and open and edit the file as follows.

Prefix: Specifies the storage path of the npm global module. The cache is the cache path. The specific structure is not clear. The general meaning is that the installed modules are in the prefix path, cache is the version and package information of some cached modules.

Method 2:

Use the following command line in the cmd window:

Npm config set prefix "D: \ nodeModule \ node_global"

Npm config set cache "D: \ nodeModule \ node_cache"

After testing, it is valid only in the current setting. After opening the cmd window again, it is still in the default path. You may need to run the cmd window as an administrator to set it successfully. If you are interested, test it yourself. Method 1: simple and quick. Haha

There are several modules to be installed. We recommend that you install them inTutorialI will not repeat it.

2.Install webstorm 11 on the Internet, including how to register webstorm. ThisAddressYou can download (password: whte), which contains registration and Chinese tutorials. Please support genuine software. You canHereDownload, select: Other. If you don't understand it, you can't do it.

3.To open webstorm 11, you may need to configure the node directory, as shown in Chinese, to create a project. File --> new project)

Create a new hello. js with two lines of code:

 

Configured as follows. node interpreteris the path of node.exe you have installed. I have already configured it. You may need to configure it for the first time you open it. Other configurations are not considered as a problem:

Find the following icon, select node. js, and change the display name to hello.

 

Return to the project interface: The following results are displayed,

Click run to run. The result is as follows:

For debugging, select debug next to it. Click the line number to add a breakpoint. Only run to the breakpoint. The following figure shows the effect after clicking:

The console displays the following results. The running port number is 51411, which is a changed port number. You need to check the port number and access the front-end.

Localhost: 51411. See the result.

In webstorm, click the following button to run to the next breakpoint. You can debug other tasks.

4.Precautions:

4.1: After modifying the code, you 'd better click the red box button and then click the bug button again. Please speak to me: restart required.

4.2: if the code is incorrect, the port prompted by debug cannot be accessed.

4.3: there are other debugging methods on the Internet. This is only the simplest method, for example, creating a service. js. The code in it is as follows,

After configuration according to the above method, you can directly access localhost: 8888 or access it. Of course, you can also expand and debug js on this page.

Var http = require ("http ");

Http. createServer (function (request, response ){

Console. log ("running to createService ");

Response. writeHead (200, {"Content-Type": "text/plain "});

Response. write ("Hello World, two ");

Response. end ();

}). Listen (8888 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.