Search code examples
node.jsfirebase-hosting

504 Time-out when deploying node.js app to Firebase


I am working on this app that is running as wxpected on localhost but once deployed to firebase hosting it throw this error

504 Gateway Time-out

The function save a file to the disk and I am afraid that a disk is not available when deploying, just like heroku when you restart the dynos.

app.get('/api', (request, response) => {
  var filename = Date.now() + '.jpg'
  webshot( url ,'public/' + filename , options, function (err) {
    if (err) {
        console.log(err);
    }
    else {
        response.send(filename);
    }
  });
})

Is that the reason I am getting the error? or it could be something else? Is it possible to store files on a node.js app once deployed?


Solution

  • Cloud Functions have a read-only file system except for /tmp which is backed by the memory of your function.

    1:30 of this Firecast has a good example of writing to /tmp.

    import * as os from 'os';
    const tmp = os.tmpdir();
    

    If you want to persist files you should look at using Cloud Storage.