title: Saving HTTP GET response to a file in a express/node app
body: <p>I have an express/node app which exposes a GET end point via express router something like /api/user. The response is a JSON and i want to download the JSON  to a file when i hit localhost:8080/api/user.</p>
  
  <p>I tried with res.download but not sure how to handle the response data with it. This could be a duplicate question but i cannot find an example especially for this use case.</p>
  
  <p>When the end point is invoked in browser it should prompt for download and then should get downloaded to the default location.</p>
  
  <pre><code>router.route('/user')
  .get((req, res) =&gt; {
  MyService.get().then((result) =&gt; { // the get method resolves a promise with the data
    // Prompt for download 
  }).catch((err) =&gt; {
    console.log(err);
  
    res.status(500).json({
      status: 500,
      data: err
    });
  });
  });
  </code></pre>