Created
          September 1, 2011 12:02 
        
      - 
      
- 
        Save davidbanham/1186032 to your computer and use it in GitHub Desktop. 
    Dynamically generate a file download in express without touching the filesystem
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var express = require('express'); | |
| var app = require('express').createServer(); | |
| app.listen('3030'); | |
| app.get('/', function(req, res) { | |
| res.contentType('text/plain'); | |
| res.send('This is the content', { 'Content-Disposition': 'attachment; filename=name.txt' }); | |
| }); | 
Express 4:
app.get('/', async (req, res) => {
    res.status(200)
        .attachment(`name.txt`)
        .send('This is the content')
})
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
saved my life