Currently I initialise the firebase emulators with:
$ firebase emulators:start
After some time working on it I want to stop it. How can I then stop the emulators?
Currently I initialise the firebase emulators with:
$ firebase emulators:start
After some time working on it I want to stop it. How can I then stop the emulators?
sudo lsof -i tcp:<port>
kill -9 <process id>
If you don't want to have to check the port every time, you can stop command with below
kill -9 (lsof -t -i:5002 -i:5001)
(-i:xxxx are your running emulator ports in firebase.json.)
Moreover, I don't want to memorize this long command. So I made package.json script below.
"scripts": {
...
"stop": "lsof -t -i :5001 -i:5002 | xargs kill -9",
...
}
I've tried all the answers above, and none does what I was expecting: to gracefully end the emulator suite as a whole without having to ctrl+c, leaving no ports occupied. Here is how I've solved it.
TLDR: lsof -ti :4400 | xargs --no-run-if-empty kill
The port being 4400, as it's the default port for the Emulator Hub. Although with this command you'll end the emulator regardless of the process you kill.
The"-9" flag used in the other answers does not send the SIGTERM signal to the process, but forcefully kills it instead. This prevents the emulator from ending gracefully.
according to this: https://github.com/firebase/firebase-tools/issues/1367 Ctrl+C
kills the emulators
An alternative is to use firebase emulators:exec
, which, according to the CLI documentation, does this:
start the local Firebase emulators, run a test script, then shut down the emulators
Since I put my test running command in a Makefile, I use the following command to test firestore from a Python firebase_admin
SDK:
firebase emulators:exec "make test" --only firestore
The set-up and tear-down of the port is handled by firebase directly.