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

4 Answers 4

44

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
6
  • I saw the download stats on npm, I wasn't the only one that wanted this feature. Well done.
    – Marcs
    Jan 6, 2019 at 20:54
  • 1
    Hi! Is It possible with your module to create one HTML report from multiple package.json in other subfolders? May 15, 2019 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, 2020 at 6:31
  • 2
    @MarkZhukovsky Are you using PowerShell? If so, you may be seeing this issue. github.com/eventOneHQ/npm-audit-html/issues/34
    – Noah Prail
    Aug 31, 2020 at 18:59
  • 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, 2021 at 18:27
7

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

1
  • As of 9-Apr-20, the file created by npm-audit-html is named npm-audit.html.
    – CAK2
    Apr 10, 2020 at 0:47
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.

2
  • 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, 2022 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. Jul 13, 2022 at 9:48
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.

2
  • I recommend Cygwin for windows/bash stuff. So long as it's minor bash scripting.
    – terary
    May 28, 2018 at 16:18
  • Cygwin is nice but I would recommend msys2 (msys2.org) as a more advanced solution.
    – Marcs
    Aug 5, 2018 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.