Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda