Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress output when running npm scripts

Tags:

node.js

npm

People also ask

What is -- silent in npm?

Silencing the output of npm install has been quite the journey. I've come across the flags --quiet and --silent . --quiet will only log errors and warnings. npm install --quiet. --silent should output nothing.

How do I stop npm from serving?

You can stop the process on the console like any other process: Ctrl + c .

How do I turn off warnings in npm?

you need to change that to npm --logevel=error install , and that will suppress the WARN message and Team Foundation Server will stop complaining about it.

What does npm ignore scripts do?

Disclosing the flaw to NPM: Essentially ignore-script is designed to prevent the execution of malicious pre/post-install scripts of packages defined inside dependencies.


All scripts:

You can fix this by suppressing the output of npm overall, by setting the log level to silent in a couple ways:

On each npm run invocation:

npm run --silent <your-script>

Or globally by creating a .npmrc file(this file can be either in your project directory or your home folder) with the following:

loglevel=silent

Resources:

npm log level config: https://docs.npmjs.com/misc/config#loglevel

npmrc: https://docs.npmjs.com/misc/config#loglevel

Each script, individually:

A simple trick I've used to get around this issue on certain scripts like linting is to append || true at the end of such scripts. This will work without any npm config changes.

This will ensure that the script will always exit with a 0 status. This tricks npm into thinking the script succeed, hence hiding the ERR messages. If you want to be more explicit, you can append || exit 0 instead and it should achieve the same result.

{
  "scripts": {
    "lint": "jshint || true",
   }
}

You should be able to use both the --quiet and --silent options, as in

npm install --quiet

--quiet will show stderr and warnings, --silent should suppress nearly everything

You can also send stdout/stderr to /dev/null, like so:

npm install > "/dev/null" 2>&1

or less versbose

npm install &> /dev/null

npm install --quiet --no-progress 

Will keep warnings and errors, and suppress the ADHD progress bar on terminals that support it.


for an individual script that you want to keep silent without having to add --silent each time, you can make a new script that calls your previous one and adds --silent.

My example scripts in package.json:

    "dev-loud": "npm run build && nodemon -r dotenv/config dist/index.js",
    "dev": "npm run dev-loud --silent"