How can I shut down the local firebase emulators?

18,983

Solution 1

  1. Check which process is occupying the port sudo lsof -i tcp:<port>
  2. Kill the process kill -9 <process id>

Solution 2

according to this: https://github.com/firebase/firebase-tools/issues/1367 Ctrl+C kills the emulators

Solution 3

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",
   ...
}

Solution 4

One cross-platform solution is to just run: npx kill-port 4000,8080,8085

Solution 5

If you wanna kill all firebase emulators you can easily do that by firing this command

$ lsof -t -i:8080 -i:9000 -i:9099 -i:9199 -i:9090 | xargs kill -9

When you don't want to type this long command each time I advise you to use a script in the package.json file

 "scripts": {
   "emulators:start": "firebase emulators:start",
   "emulators:stop": "lsof -t -i:5001 -i:5002 -i:8080 -i:9000 -i:9099 -i:9199 -i:9090 | xargs kill -9"
  }

One for starting your emulators and one for stopping, in case Ctr+C didn't stop the processes in the background.

Those are the default PORTS from the documentation page in firebase. You should also check your firebase.json file and replace the PORTS in the previous command if they are different.

Share:
18,983
user1447414
Author by

user1447414

Updated on June 14, 2022

Comments

  • user1447414
    user1447414 almost 2 years

    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?

  • ra9r
    ra9r over 3 years
    I have found that if you exit VSCode without shutting down the emulators first it can remain running and without the above commands, you will need to restart the computer to be able to restart the emulators. Thank you for sharing @xmkevinchen
  • ThdK
    ThdK over 3 years
  • perepm
    perepm over 3 years
    @ra9r on linux the process is called java. If you kill it you won't need to restart your computer.
  • user3875913
    user3875913 about 3 years
    this was it for me, though --no-run-if-empty is bogus on macOS
  • cyber_angel
    cyber_angel about 3 years
    I'm flabbergasted there is no shutdown command...this is an insane workflow.
  • Jeff Neet
    Jeff Neet over 2 years
    This seems like such an obvious feature to include in a command firebase emulators:stop or similar, it makes me think I'm using the tool wrong. Is the normal workflow to start up the emulators and leave them running in the background while developing for long periods of time?
  • Alberto Oliveira
    Alberto Oliveira about 2 years
    Faster option, and work in windows and Linux
  • Johann
    Johann about 2 years
    Nope. Doesn't work on a MacBook.
  • monsto
    monsto about 2 years
    Nothing like a little automation to simplify your day.
  • monsto
    monsto about 2 years
    @JeffNeet that's the way I use it. I fire up the function/firestore emulators and work on event functions and db triggers. Sometimes it completely blows out and stops with an error leaving the process running which is when I need the answer below by user kazuwombat. Generally tho, 2x Ctrl-C is enough.