Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
Error getting public folder with express in firebase

I'm having this issue when try to get /public folder with express in firebase.

My project tree are:

ProjectRoot  
├───functions -> index.js  
├───node_modules  
├───public -> index.html  
└───firebase.json  

Im trying to get /public/index.html from /functions/index.js.

This is my index.js

const functions = require('firebase-functions');
const express = require("express");
var path = require('path');

const app = express();

// Static files
app.use("/public", express.static(path.join(__dirname , '/..' , "/public")));

// Routes
// Test1 is actually working
app.get("/test1", (req, res) => {
    try{
        res.send('🔥Module 1 is on fire🔥');
    }catch(error){
        console.error("Error Debug: "+ error);
    }
});
// Test2 isn't working
app.get("/test2", (req, res) => {
    try{
        res.sendFile('/public/index.html');
    }catch(error){
        console.error("Error Debug: "+ error);
    }
});
// Test3 isn't working
app.get("/test3", (req, res) => {
    try{
        res.sendFile(path.join(__dirname,'/..','/public/index.html'));
    }catch(error){
        console.error("Error Debug: "+ error);
    }
});
exports.app = functions.https.onRequest(app);

The console throw me chronologically

Function execution took 6 ms, finished with status code: 200 --> Test1 Works
ENOENT: no such file or directory, stat '/public/index.html' Test2 code 404
ENOENT: no such file or directory, stat '/public/index.html' Test3 code 404

And finally my firebase.json are

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]
  },
  "functions": {
    "source": "/functions",
    "runtime": "nodejs16"
  }
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!