Now we introduce a JS code verification tool Jshint to check for simple errors under node.
Jshint Specific Introduction Reference http://www.jshint.com/about/, say plainly, Jshint is a check JS code specification or not tool, It can be used to check the normalization of any JS code (both server-side and client-side). It provides a configuration approach that allows developers to define which specifications are checked for errors. This gives developers a lot of convenience, because in the development process, especially during the team development process, you often encounter a variety of problems caused by the failure of 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:
Copy Code code as follows:
NPM install-g jshint//-g means global use
Note: If NPM is not an internal or external command, you probably don't have node or NPM installed. Please refer to http://dailyjs.com/2012/05/03/windows-and-node-1/for specific installation process.
2, run Jshint.
Open the CMD Command window, use the CD to switch to your corresponding application directory, enter the command:
Copy Code code as follows:
Note: My_app.js is the file that you intend to verify or check.
3, configure Jshint.
Jshint provides a configuration method that allows you to define rules for checking checksums based on your team or hobby. You can copy the default rule file to Https://github.com/jshint/node-jshint/blob/master/.jshintrc.
Method One: If you name the copied rule file as a. jshintrc file and place the file in the corresponding directory or parent directory, the rule file is automatically retrieved and used when you run Jshint.
Method Two: If you do not name the rule file in accordance with the rule name (that is, with. jshintrc), then you can manually specify the rule file when you run Jshint, for example, you name the rule file Jshint.json. Then you can use the command to run Jshint and apply your rules:
Copy Code code as follows:
Jshint my_app.js--config/root/application/jshint.json//Specify Rule file path
4, the rules of the configuration file.
There are a number of rules for the configuration file, including common semicolons or not, and the first letter of the class constructor function. The specific rules no longer one by one repeat, please refer to http://www.jshint.com/docs/.
By using the Jshint tool, you will check out many of the common mistakes or errors in your JS code. Of course, Jshint won't be strong to check out all your mistakes. But don't worry, there are several other debugging tools that you can use for node, this time just introduce jshint.
The above is my humble opinion, if there is any mistake, please point out. Welcome to the exchange of discussions.