3

When I start the emulators, the Storage emulator starts and is available at localhost:9199.
Then I access storage with the admin SDK in node.js with:

serviceAccountKey = require('./serviceAccountKey.json');
const config = {
  credential: admin.credential.cert(serviceAccountKey),
};
const adminApp = admin.initializeApp(config);
const storage = adminApp.storage();

Now storage points to the emulator, not the real service as before this emulator has been implemented.
How can I get access to the real service?
I have tried setting projectId and the env variable as described here, but it does not work.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Louis Coulet
  • 3,663
  • 1
  • 21
  • 39

2 Answers2

4

OK, so the way is simply to start all services but storage from the command line, and not from firebase.json, this way:

firebase emulators:start --only hosting,functions,firestore,auth,ui
Louis Coulet
  • 3,663
  • 1
  • 21
  • 39
2

Running firebase emulators:start will start all services in an emulated state. If you want to talk to a production service, you can run firebase serve, or if you want some services emulated but not storage, you can run firebase serve --only {services,to,emulate} (eg, firebase serve --only functions,hosting. This would emulate functions and hosting, but any call to storage (or auth or other non-emulated services) would talk to the live Firebase environment.

I'm Joe Too
  • 5,468
  • 1
  • 17
  • 29
  • 1
    Thanks for your answer, but I would rather keep using *emulators* instead of *serve* because the latter [seems to be deprecated](https://stackoverflow.com/a/56620511/6016470) and only emulates [hosting and functions triggered by HTTP requests](https://stackoverflow.com/a/56620511/6016470). Also, up until *storage* has been added to the emulator suite, the command *emulators:start* only started the services listed in [firebase.json](https://firebase.google.com/docs/emulator-suite/install_and_configure#configure_emulator_suite). – Louis Coulet Jul 23 '21 at 13:15