Now we introduce JSHint, a JS code verification tool for checking simple errors under Node.
For a detailed introduction to JSHint, please refer to http://www.jshint.com/about/. To put it bluntly, JSHint is a tool for checking whether the JS code is standardized. It can be used to check any (including server-side and client side) the standardization of JS code. It provides configuration methods, allowing developers to define which specification errors to check. This brings great convenience to developers, because during the development process, especially during team development, we often encounter various problems caused by non-compliance with specifications, or some common text Errors, such as using undefined functions or parameters, etc.
1. Install JSHint.
Open the cmd command window and enter the following command:
Note: If it says that npm is not an internal or external command, then it is probably because you have not installed node or npm. For the 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, and enter the command:
Note: my_app.js is the file you intend to verify or check.
3. Configure JSHint.
JSHint provides a configuration method so that you can define verification rules according to your team or hobbies. You can copy the default rule file from https://github.com/jshint/node-jshint/blob/master/.jshintrc.
Method 1: If you name the copied rule file as a .jshintrc file and place the file in the corresponding directory or parent directory, this rule file will be automatically retrieved and used when running JSHint.
Method 2: If you have not named the rule file a name that conforms to the rules (that is, use .jshintrc), you can manually specify the rule file when running JSHint. For example, you name the rule file jshint.json. Then you can use the following command to run JSHint and apply your rules:
4. Configuration file rules.
There are many rules for configuration files, including the common use of semicolons, capitalization of the first letter of class constructor functions, etc. The specific rules will not be repeated one by one. Please refer to http://www.jshint.com/docs/.
By using the tool JSHint, many common errors or accidentally mistaken codes in your JS code will be checked. Of course, JSHint won't be powerful enough to catch all your errors. But don’t worry, there are several other debugging tools that can be used for Node. This time I will only introduce JSHint.
The above is my humble opinion. If there are any mistakes, please point them out. Welcome to exchange and discuss.