title: How to show a loader in node js application
body: <p>I am developing a node js application. In my application, I am calling the script file from node js app. </p>
  
  <p>In that script file, I am creating a HDI cluster in azure.</p>
  
  <p>I want to show a spinner till the script completes the creation of HDI cluster and hide the spinner after script execution.</p>
  
  <p>How can I show using Node js application? Provide me an example?</p>
  
  <p>index.js</p>
  
  <pre><code>&lt;div class="container"&gt;
    &lt;fieldset&gt;
      &lt;form action="/" method="post"&gt;
        &lt;h4&gt;Create Cluster&lt;/h4&gt;&lt;br&gt;&lt;br&gt;
        &lt;label for="name"&gt; Name:  &lt;/label&gt;
        &lt;input name="name" type="text" class="name" placeholder="Enter a name" required&gt;&lt;br&gt;&lt;br&gt;          
        &lt;input type="submit" class="button" value="Create"&gt;
      &lt;/form&gt;
    &lt;/fieldset&gt;
    &lt;div id="load"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>server.js</p>
  
  <pre><code>app.post('/', function (req, res) {
    res.render('index');
  
      var child = exec('bash sample.sh');
  
    child.stdout.on('data', function(data) {
      logger.info(data)
    });
  
    child.stderr.on('data', function(data) {
      logger.error(data);
    });
  
    child.on('close', function(code) {
      logger.info('Script exit code: ' + code);
    });
  })
  </code></pre>
  
  <p>sample.sh</p>
  
  <pre><code>#!/bin/bash
  set -euo pipefail
  IFS=$'\n\t'
  
  # -e: immediately exit if any command has a non-zero exit status
  # -o: prevents errors in a pipeline from being masked
  # IFS new value is less likely to cause confusing bugs when looping arrays or arguments (e.g. $@)
  
  usage() { echo "Usage: $0 -i &lt;subscriptionId&gt; -g &lt;resourceGroupName&gt; -n &lt;deploymentName&gt; -l &lt;resourceGroupLocation&gt;" 1&gt;&amp;2; exit 1; }
  
  declare subscriptionId=""
  declare resourceGroupName=""
  declare deploymentName=""
  declare resourceGroupLocation=""
  
  # Initialize parameters specified from command line
  while getopts ":i:g:n:l:" arg; do
      case "${arg}" in
          i)
              subscriptionId=${OPTARG}
              ;;
          g)
              resourceGroupName=${OPTARG}
              ;;
          n)
              deploymentName=${OPTARG}
              ;;
          l)
              resourceGroupLocation=${OPTARG}
              ;;
          h)
              echo "This message"
          esac
  done
  shift $((OPTIND-1))
  
  #Prompt for parameters is some required parameters are missing
  if [[ -z "$subscriptionId" ]]; then
      echo "Your subscription ID can be looked up with the CLI using: az account show --out json "
      echo "Enter your subscription ID:"
      read subscriptionId
      [[ "${subscriptionId:?}" ]]
  fi
  
  if [[ -z "$resourceGroupName" ]]; then
      echo "This script will look for an existing resource group, otherwise a new one will be created "
      echo "You can create new resource groups with the CLI using: az group create "
      echo "Enter a resource group name"
      read resourceGroupName
      [[ "${resourceGroupName:?}" ]]
  fi
  
  if [[ -z "$deploymentName" ]]; then
      echo "Enter a name for this deployment:"
      read deploymentName
  fi
  
  if [[ -z "$resourceGroupLocation" ]]; then
      echo "If creating a *new* resource group, you need to set a location "
      echo "You can lookup locations with the CLI using: az account list-locations "
  
      echo "Enter resource group location:"
      read resourceGroupLocation
  fi
  
  #templateFile Path - template file to be used
  templateFilePath="template.json"
  
  if [ ! -f "$templateFilePath" ]; then
      echo "$templateFilePath not found"
      exit 1
  fi
  
  #parameter file path
  parametersFilePath="parameters.json"
  
  if [ ! -f "$parametersFilePath" ]; then
      echo "$parametersFilePath not found"
      exit 1
  fi
  
  if [ -z "$subscriptionId" ] || [ -z "$resourceGroupName" ] || [ -z "$deploymentName" ]; then
      echo "Either one of subscriptionId, resourceGroupName, deploymentName is empty"
      usage
  fi
  
  #login to azure using your credentials
  az account show 1&gt; /dev/null
  
  if [ $? != 0 ];
  then
      az login
  fi
  
  #set the default subscription id
  az account set --subscription $subscriptionId
  
  set +e
  
  #Check for existing RG
  az group show $resourceGroupName 1&gt; /dev/null
  
  if [ $? != 0 ]; then
      echo "Resource group with name" $resourceGroupName "could not be found. Creating new resource group.."
      set -e
      (
          set -x
          az group create --name $resourceGroupName --location $resourceGroupLocation 1&gt; /dev/null
      )
      else
      echo "Using existing resource group..."
  fi
  
  #Start deployment
  echo "Starting deployment..."
  (
      set -x
      az group deployment create --name "$deploymentName" --resource-group "$resourceGroupName" --template-file "$templateFilePath" --parameters "@${parametersFilePath}"
  )
  
  if [ $?  == 0 ];
   then
      echo "Template has been successfully deployed"
  fi
  </code></pre>