title: How to return files saved on a file system with Node js and Multer to angular front-end?
body: <p>I'm new to programming with angular and node js, and I need to return the files that are saves in a file system (handled by the backend in node js) to the front end, to give the user the option to view them or download them, to save them I used the multer middleware, but to bring them back for the front end I not found a effective solution.
  I tried using fs to create a buffer array, but it didn't work.
  Does anyone jnow an effective solution?</p>
  
  <p>In the request will be passed parameters to identify which file returns, but for now I'm testing with a static file.</p>
  
  <p>My request : </p>
  
  <pre><code>let headers: Headers = new Headers(); 
  headers.append('Content-type', 'application/json'); 
  headers.append('Authorization', token); 
  let link = ${URL_AuthAPI}/systemUsers/list; 
  
  let body = JSON.stringify({ obj }); 
  let option = new RequestOptions({ headers: headers }); 
  return this.http.post(link, body, option).map((resposta: Response)=&gt; resposta);
  </code></pre>
  
  <p>Nodejs Server: </p>
  
  <pre><code>var filePath = path.join("/home", 'rg.png');
    var stat = fileSystem.statSync(filePath);
  
      res.writeHead(200, {
          'Content-Type': 'image/png',
          'Content-Length': stat.size,
          // 'Content-Disposition': 'attachment ; filename=teste.png'
      });
  
      var readStream = fileSystem.readFileSync(filePath);
  
      readStream.on('data', function(data) {
      response.write(data);
  });
  
  readStream.on('end', function() {
      response.end();        
  });
  </code></pre>
  
  <p>Component Code: </p>
  
  <pre><code>this.systemUsersService.listUsers(this.token, null).subscribe((apiResponse) =&gt; {
  
        var data = apiResponse['_body'];
        console.log(data);
  
      }, (error: any) =&gt; {
  
      }
      );
  </code></pre>