As posed in the question, I know there exists the possibility to use npm run -s somescript, but I want to know if there's a way to have it already by default there, any ideas?
{
"description": "Some node demo server",
"main": "server.js",
"scripts": {
"start": "node server.js",
"somescript": "echo \"I want this script to run silently\""
},
"author": "SomeDude"
}
Edit:
Sorry I did't specify well my needs, so I would like to just have:
> [email protected] somescript /my-app ##I don't care if this appears or not
I want this script to run silently ## This would be echo's output, I want to see the echo output
But not:
> [email protected] somescript /my-app ##I don't care if this appears or not
> echo \"I want this script to run silently\" ## I don't want this line
I want this script to run silently ## I just want this, the ouput
dev null still makes this line which I don't want to appear:
> echo \"I want this script to run silently\" ## I don't want this
OS: Ubuntu 16.04 LTS
To define an NPM script, set its name and write the script under the 'scripts' property of your package. json file: To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably.
The --ignore-scripts argument will cause npm to not execute any scripts defined in the package. json. See scripts . The --legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package.
Npm is a tool that use to install packages. Npx is a tool that use to execute packages. Packages used by npm are installed globally. You have to care about pollution in the long term. Packages used by npx are not installed globally.
Scripts are stored in a project's package. json file, which means they're shared amongst everyone using the codebase. They help automate repetitive tasks, and mean having to learn fewer tools. Node npm scripts also ensure that everyone is using the same command with the same flags.
If you're script is running on Mac or Linux, you can add > /dev/null
to the end of your script and it will print nothing to the console. Pretty silent if you ask me. Though I'd recommend that you have some kind of file logger so you can see any errors that happen.
example:
node server.js > /dev/null
What you need to note is that it will show you the command line its executing when you put it into the npm scripts.
```bash bjemilo:test$ npm run somescript
[email protected] somescript /Users/bjemilo/Desktop/test echo "I want this script to run silently" > /dev/null ```
However removing the /dev/null producing this
```bash bjemilo:test$ npm run somescript
[email protected] somescript /Users/bjemilo/Desktop/test echo "I want this script to run silently" > /dev/null
I want this script to run silently ```
This is expected behavior. But there is a work around if you add /dev/null to the npm command.
With npm in terminal
npm run somescript > /dev/null
It prints nothing.
Doing npm run --silent somescript
does the same result
You could always just create a bash/shell script to run the command. npm scripts is there for convenience and it has nice hooks that can run before and after a script call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With