Search code examples
firebaseexpressfirebase-hostingfirebase-app-hosting

Attempting to deploy a simple Express app on Firebase App Hosting


Most of the questions related to hosting this kind of app are related to the original Firebase Hosting. In this case I'm attempting to use the "App Hosting" different from the Firebase Hosting.

Here are my steps. I setup a git repository with a simple express app.

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

I connect the github repository with Firebase App Hosting. Everything links and then it begins the in progress. It then gives me an error message that the roll out failed. The build log reports no specific errors. It actually says "Successful". Is there other settings I have to set like the specific port etc? Any idea what I'm missing here? enter image description here enter image description here


Solution

  • Firstly, the documentation for Firebase App Hosting doesn't say anything about support for Express apps:

    App Hosting provides no-config-needed build and deploy support for Web apps developed in these frameworks:

    • Next.js 13+
    • Angular 17.2+

    Secondly, App Hosting is built on top of Cloud Functions (actually Cloud Run now) for the backend parts, and that backend code can't use app.listen. The Cloud Run infrastructure listens automatically for you, and you just provide an Express app to handle the incoming requests.

    If you want to deploy an Express app using Firebase, you should refer to Firebase's Cloud Functions documentation instead of App Hosting. Also see Firebase Hosting documentation if you want to serve the app deployed to Cloud Functions over Firebase Hosting.