30

Is there a way to display the npm audit report as an html page?

At the moment i can only see the option to output the report in json format, using this command:

npm audit --json

Marcs
  • 3,768
  • 5
  • 33
  • 42

4 Answers4

43

I wrote an NPM package that does this for you.

You can use it by running the following:

// first install it
npm i -g npm-audit-html

// then pipe npm audit to it
npm audit --json | npm-audit-html
Noah Prail
  • 644
  • 6
  • 10
  • I saw the download stats on npm, I wasn't the only one that wanted this feature. Well done. – Marcs Jan 06 '19 at 20:54
  • 1
    Hi! Is It possible with your module to create one HTML report from multiple package.json in other subfolders? – Luca Mormile May 15 '19 at 13:11
  • 4
    I'm getting "no input" for some reason as a result - but npm audit --json definitely produces output.. – Mark Z. Aug 31 '20 at 06:31
  • 2
    @MarkZhukovsky Are you using PowerShell? If so, you may be seeing this issue. https://github.com/eventOneHQ/npm-audit-html/issues/34 – Noah Prail Aug 31 '20 at 18:59
  • I think you can use the > instead. npm audit --json > npm-audit-html – Jonathan Jun 09 '21 at 13:13
  • 3
    From a PowerShell prompt you need to pass the whole thing to cmd because PS won't pipe output between non-PS things `cmd /c 'npm audit --json | npm-audit-html'` – davidmdem Nov 18 '21 at 18:27
7

Following previous answers...
As of NPM v7, you'll need the beta version of npm-audit-html.

npm install -g npm-audit-html@beta
npm audit --json | npm-audit-html --output report.html

For more details: https://github.com/eventOneHQ/npm-audit-html/issues/43#issuecomment-940159989

P.S. Tested with NPM v8.3.0.

Noam Gal
  • 1,124
  • 1
  • 11
  • 15
  • 3
    Thanks! I previously got 'No data available in table' and 0 dependencies in the html file. With the beta version, it's now working (using npm v8.9.0). – dreiekk May 18 '22 at 19:33
  • Was looking for a native way without installing any new dependency, but there doesn't seem to be any way to get HTML output. – Sahil Babbar Jul 13 '22 at 09:48
6

npm-audit-html is a good package, just used it.

npm install -g npm-audit-html
npm audit --json | npm-audit-html --output report.html

If you are getting the "No Input" response when running through powershell or VS Code Terminal just run it with the command prompt

FabianDev
  • 131
  • 2
  • 4
1

On Linux I'm using ccat in a bash script:

#!/bin/sh

echo "<!DOCTYPE html><head><meta charset=\"UTF-8\"/></head><body>"
npm audit|ccat --html
echo "</body></html>"

Usage: ./audit.sh > vulnerabilities.html

But I'm also interested in other solutions, maybe ones that could work on Windows too.

Marcs
  • 3,768
  • 5
  • 33
  • 42