npm script shortcuts
Use npm scripts for frequently used commands
You can use the npm scripts to run bash scripts, and unleash the unlimited power of scripting.
You don’t have to memorize all your commands and their parameters.
If you frequently use certain commands, consider adding them to your package.json file as a script. For instance, if you want to use sfdx command to deploy the content of your force-app folder, you can do this simply:
"scripts" : {
"deploy:all": "sf project deploy start --source-dir force-app -w"
}Now to execute your sfdx command you can type the following command in terminal:
npm run deploy:allCheck the next page to see another examples
You can use the npm scripts to run bash scripts, and unleash the unlimited power of scripting.
"scripts": {
"hello": "bash hello.sh"
}Create a file ‘hello.sh’ with the script (in this case it should belong to the root folder of your project):
#!/bin/bash
echo "Hello World"Now to execute your bash script you can type the following command in terminal:
npm run helloAnother useful example is to run the Anonymous Apex. Let me show you how this could be used to enable debug mode without using UI.
"scripts": {
"debug-mode": "sfdx apex:execute -f \"debugMode.apex\""
}Create an apex script in file ‘debugMode.apex’
update new User(Id = UserInfo.getUserId(), UserPreferencesUserDebugModePref = true);Now to execute your sfdx command you can type the following command in terminal:
npm run debug-modeDon’t forget, also to check what the npm scripts that are already existing in your package.json file.
There are probably some useful commands already created there.

I would also recommend checking a great article about npm scripts by Philippe Ozil (link in the comment)
Do you have any favourite npm scripts that boost your productivity? Share them in the comments!
Also, don’t forget to follow our page to get other examples and tips!


