Search code examples
npmcomments

How exactly do you use NPM scripts and echo while executing a command?


I cannot find any documentation on displaying messages in the terminal when executing NPM scripts.

For instance "bsync": "echo 'Starting BrowserSync' browser-sync start" does not work.


Solution

  • You can create bash script

    Create any script you like (and even complex scripts)

    Add the script to the your bin folder or to your /node_modules/.bin folder

    And then add the following in your script section in package.json

     "scripts": {
        "bsync": "./bin/echo.sh"
      }
    

    and create your echo.sh script:

    #!/bin/bash
    
    echo 'Starting BrowserSync' browser-sync start
    

    The other option is to direct echo

    "scripts": {
        "bsync": "echo \"Starting BrowserSync\" && exit 1"
      }