Book Image

Mastering Web Application Development with Express

By : Alexandru Vladutu
Book Image

Mastering Web Application Development with Express

By: Alexandru Vladutu

Overview of this book

Table of Contents (18 chapters)
Mastering Web Application Development with Express
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Complexity analysis of our code


Complex code is hard to read, test, and work on, even more so if we're trying to decipher somebody else's code. Fortunately, there's a tool to measure code complexity called complexity-report (https://www.npmjs.org/package/complexity-report).

As always, we need to install the module first so that we can use it:

$ npm i complexity-report ––save-dev

When running this tool, we must specify which folders it should ignore, so that we don't get reports for the dependencies used or code-coverage files:

$ ./node_modules/.bin/cr . --dirpattern '^((?!(test|node_modules|coverage)).)*$'

A sample output could look like the following screenshot:

We can also specify the desired format, which can be one of the following: plain, markdown, minimal, JSON, and XML.

Just like the code-coverage tool, this one also supports thresholds for things such as cyclomatic complexity or Halstead difficulty threshold. These represent software metrics that determine the complexity of a program...