In package.json
there is a script
section. From here one can run NPM Scripts.
"scripts": {
"one": "scriptOne.js",
"two": "scriptTwo.js"
}
These can be run like this.
npm run one
This particular line will run scriptOne.js
. This is powerful as we could take Node’s power and run any automated task for ourselves.
At first this seemed simple to me. Soon I came across cross-platform bugs. Since we are writing this in JS
, it could be run anywhere Node
is available. Now that could be a tricky thing. Some environments deal with certain things in a certain way. This is not a big thing if the script is written to handle those situations. Another thing is Node
versions. If the script is written using certain API of a particular Node
version, it is better to keep an eye on new releases of Node and update the script if there are breaking changes.
Note for a better script writing and running:
- The script should work in crossplatform environments
- Keep an eye on Node version while running the script ( It may be possible, the script is written using newer version of Node than you are currently running it on. )