Installation and configuration tutorial for Node debugging tool JSHint

  • 2020-03-30 03:06:36
  • OfStack

Now we introduce JSHint, a JS code validation tool that checks for simple errors under Node.

JSHint refer to the detailed introduction of http://www.jshint.com/about/, said bluntly, JSHint is a tool inspection JS code specification or not, it can be used to check for any (including server side and client side) where the standardization of JS code. It provides a way to configure it so that developers themselves can define which specifications to check for errors. This brings great convenience to developers, because in the development process, especially in the development process of the team will often encounter various problems caused by non-compliance with the specification, or some common text errors, such as using undefined functions or parameters.

1. Install JSHint.

Open the CMD command window and enter the following command:


npm install -g jshint  //-g means global use

Note: if the NPM is not an internal or external command, it is likely that you have not installed node or NPM. Specific installation process, please refer to http://dailyjs.com/2012/05/03/windows-and-node-1/.

2. Run JSHint.

Open the CMD command window, use CD to switch to your corresponding application directory, enter the following command:


jshint my_app.js

Note: my_app.js is the file you intend to verify or check.

Configure JSHint.

JSHint provides configuration methods that allow you to define the rules for checking checkouts based on your team or hobby. Able to copy the default rules file to https://github.com/jshint/node-jshint/blob/master/.jshintrc.

Method 1: if you name the copied rule file.jshintrc and place the file in the corresponding directory or parent directory, the rule file will be automatically retrieved and used when running JSHint.

Method 2: if you do not name the rule file with a name that matches the rule (i.e. Jshintrc), you can manually specify the rule file when running JSHint, for example, if you name the rule file jshint.json. Use the following command to run JSHint and apply your rule:


jshint my_app.js --config /root/application/jshint.json  //Specifies the path to the rule file

4. Rules for configuration files.

The rules for configuration files are many, including common semicolons, class constructor initializations, and so on. Specific rules no longer to detail, please refer to http://www.jshint.com/docs/.

By using the JSHint tool, you will be able to check out many common errors or careless errors in your JS code. Of course, JSHint is not powerful enough to check out all your errors. Don't worry, though, there are several other debugging tools available for Node, and this time I'll just cover JSHint.

The above is my simple opinion, if there is a mistake, please point out. Welcome to the discussion.


Related articles: