Question: I am looking for a solution to directly download a file in the Firebase Storage when hitting an API endpoint. I tried initializing a Google-Cloud Storage and downloading the file from the bucket.

```
const app = require('express')();
const { Storage } = require("@google-cloud/storage");

const storage = new Storage({keyFilename: keyPath});

app.get("/download", (req, res) => {
    storage.bucket(bucketName).file("file.txt").download({destination: './file.txt'});
});

app.listen(8080);

```

But this does not work!

I simply get:

```
UnhandledPromiseRejectionWarning: Error: Not Found

```

Could someone help me, please?

Answer: 
Where did you initialize the `app`

> 
> Original answer:
> 
> 
> 

```js
// Dependencies
const express = require('express')

const PORT = process.env.PORT || 3002;

// Initialize the App
const app = express();

// Start the app
app.listen(PORT, () => {
    console.info(`Server is listening on port ${PORT}`);
});

```

> 
> Update:
> Making HTTP requests to download files is an asynchronous operation. You need to wait for the file to be downloaded from the Google Cloud Storage before sending it to the client
> 
> 
> 

```js
const app = require('express')();
const { Storage } = require("@google-cloud/storage");
const storage = new Storage({keyFilename: keyPath});

// I am using async/await here
app.get("/download", async (req, res) => {

// You have to wait till the file is downloaded
    await storage.bucket(bucketName).file("file.txt").download({destination: './file.txt'});
// Send the file to the client
res.download('./file.txt')
});

app.listen(8080);

```
If the intention is to stream the file to the requesting client, you can pipe the data from Cloud Storage through to the response. It will look similar to the following:

```
const {Storage} = require('@google-cloud/storage');
const express = require('express');

const BUCKET_NAME = 'my-bucket';

const app = express();
const storage = new Storage({keyFilename: './path/to/service/key.json'});

app.get("/download", (req, res) => {
    storage.bucket(bucketName).file("path/in/bucket/to/file.txt").createReadStream()
      .on('error', (err) => {
        res.status(500).send('Internal Server Error');
        console.log(err);
      })
      .on('response', (storageResponse) => {
        // make sure to check storageResponse.status

        res.setHeader('content-type', storageResponse.headers['Content-Type']);
        res.setHeader('content-length', storageResponse.headers['Content-Length']);
        res.status(storageResponse.status);
        // other headers may be necessary

        // if status != 200, make sure to end the response as appropriate. (as it won't reach the below 'end' event)
      })
      .on('end', () => {
        console.log('Piped file successfully.');
        res.end();
      }).pipe(res);
});

app.listen(8080);

```