Search code examples
node.jsfirebaseexpressgoogle-cloud-functionsfirebase-cli

How to run an Express API via Firebase Cloud Functions locally?


I have a standard REST API using Express, exposed via a Firebase Cloud Function.

const api = express()

api.get('/test', (req, res) => res.status(403).json({ "REASON": "UNAUTHORIZED" }))

exports.api = functions.https.onRequest(api)

Remote

When I deploy it and send GET https://<remote>/api/test via Postman I get 403 { "REASON": "UNAUTHORIZED" } as expected.

Local

When I run firebase emulators:start --only functions to serve these functions locally and test them, I do see functions: HTTP trigger initialized at http://localhost:5001/.../api in my terminal, but when I send GET http://localhost:5001/.../api/test via Postman I get 200 Not Found.

Am I missing something?


Solution

  • It was indeed a defect in the Firebase CLI, it seems to be fixed in the latest version (7.13.1)

    Installed the latest version using: npm install -g firebase-tools@latest

    Note: it did require me to update to compatible version of firebase-functions and firebase-admin as well.