Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - start a process (firebase emulators) and read its output

I want to start firebase emulators before Jest tests.

Execute this, but programatically:

E:\my-projct>firebase emulators:start --only firestore
i  emulators: Starting emulators: firestore
i  firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
!  firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i  firestore: Emulator logging to firestore-debug.log
+  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
+  All emulators started, it is now safe to connect.

Therefore, I need to:

  • Execute the command

  • Wait for the "All emulators started" string to appear.

How do I read the output?

I have tried the following, all it prints is a newline.

const cp = require('child_process');
const child = cp.exec('firebase emulators:start --only firestore');
child.stdout.addListener('data', data => console.log(data.toString()));
like image 320
John Smith Avatar asked Nov 03 '25 21:11

John Smith


1 Answers

This is exactly why we have made the firebase emulators:exec command.

So let's say you use "npm run test" to run your Jest scripts, you would use:

firebase emulators:exec "npm run test"

This will:

  1. Start the emulators and wait till they're ready
  2. Run your script (npm run test in this case)
  3. Wait for your script to exit
  4. Cleanly shut down the emulators
like image 61
Sam Stern Avatar answered Nov 06 '25 10:11

Sam Stern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!