title: Problem running JS file with firebase emulators: exec
body: <p>I was trying out the new <strong>Firebase Emulators UI</strong> <a href="https://firebase.googleblog.com/2020/05/local-firebase-emulator-ui.html" rel="nofollow noreferrer">announced on May 21, 2020</a>. In the <a href="https://firebase.google.com/docs/emulator-suite/install_and_configure#startup" rel="nofollow noreferrer">Firebase Docs</a>, I noticed that there is a CLI command that allows us to run a <em>script file</em>:</p>
  
  <blockquote>
    <p><code>firebase emulators:exec scriptpath</code></p>
    
    <p>Run the script at <code>scriptpath</code> <strong>after starting emulators</strong> for the
    Firebase products configured in firebase.json. Emulator processes will
    automatically stop when the script has finished running.</p>
  </blockquote>
  
  <p>Although the docs does not mention what kind of script file it should be, I presume it could be either a <em>test script</em> or a workable <em>JavaScript file</em> that be executed standalone with <code>node filename.js</code> without any errors. This makes sense because I can actually run an initial JS file that pre-populate some test data to the <strong>Firestore Emulator</strong> for further testing.</p>
  
  <p>But since I've previously started the emulators, I have to open a new instance of command window to run the <code>firebase emulators:exec</code> command. Unfortunately, I hit the following errors:</p>
  
  <pre><code>D:\Firebase\my-project&gt;firebase emulators:exec setup-db.js
  i  emulators: Starting emulators: functions, firestore, database, hosting, pubsub
  !  hub: emulator hub unable to start on port 4400, starting on 4401 instead.
  !  emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.
  i  emulators: Shutting down emulators.
  i  hub: Stopping emulator hub
  !  functions: Port 5001 is not open on localhost, could not start Functions Emulator.
  !  functions: To select a different host/port, specify that host/port in a firebase.json config file:
        {
          // ...
          "emulators": {
            "functions": {
              "host": "HOST",
              "port": "PORT"
            }
          }
        }
  i  emulators: Shutting down emulators.
  
  Error: Could not start Functions Emulator, port taken.
  </code></pre>
  
  <p>Take note of this line:</p>
  
  <p><code>!  emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.</code></p>
  
  <p>So, how can I run the <code>firebase emulators:exec</code> <strong>AFTER the emulators start</strong> as mentioned in the Firebase Docs and, can I run the JS file for the said purpose? Thanks in advance!</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>If I run just the <code>firebase emulators:exec setup-imtp-db.js</code> without prior running the <code>firebase emulators:start</code> command, I ran into the following errors:</p>
  
  <p><a href="https://i.stack.imgur.com/QzXod.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QzXod.png" alt="enter image description here"></a></p>
  
  <p>Note that the <code>setup-imtp-db.js</code> does not contain any <strong>Cloud Functions</strong> code but just a standalone JS file that populates data from another JSON file into Firestore via Admin SDK. I'm using <code>Node.js 12.14.0</code> and <code>firebase-tools 8.4.0</code>.</p>