Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. You can automate tasks using the npm command. In practice, you can only create new executable commands running npm run command_name. To declare those new commands, just create them inside the attribute scripts on package.json like this example bellow:
  2.  
  3. ```{
  4. "name": "my-first-node-app",
  5. "description": "My first node app",
  6. "author": "User <user@email.com>",
  7. "version": "1.2.3",
  8. "private": true,
  9. "scripts": {
  10. "start": "node app.js",
  11. "clean": "rm -rf node_modules",
  12. "test": "node test.js"
  13. },
  14. "dependencies": {
  15. "module-1": "1.0.0",
  16. "module-2": "~1.0.0",
  17. "module-3": ">=1.0.0"
  18. },
  19. "devDependencies": {
  20. "module-4": "*"
  21. }
  22. }
  23. ```
  24.  
  25. Note that this new package.json created three scripts: start, clean and test. These scripts are executable now via their commands: npm run start, npm run clean and npm run test. As shortcut, only the start and test commands can be executed by the alias: npm start and npm test. Within the scripts, you can run both the commands node, npm or any other global command from the OS. The npm run clean is an example of a global command from the bash, which internally runs the command: rm -rf node_modules to deletes all files from the node_modules folder.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement