title: How to save pdf file in mysql with node.js?
body: <p>I am using node.js with mysql, and I want to save pdf file which downloads from url and save it in database.
  I have written my code here.</p>
  
  <pre><code>exports.pdf = function(req, response) {    
    var url ="http://www.ieee.org/documents/ieeecopyrightform.pdf";
    http.get(url, function(res) {
     console.log("sss");
     var chunks = [];
     res.on('data', function(chunk) {
      console.log('start');
      chunks.push(chunk);
     });
    res.on("end", function() {
      console.log('downloaded');
      var jsfile = new Buffer.concat(chunks);
      console.log('converted to base64');
      response.header("Access-Control-Allow-Origin", "*");
      response.header("Access-Control-Allow-Headers", "X-Requested-With");
      response.header('content-type', 'application/pdf');
    });
    }).on("error", function() {
    console.log("error");
    }); 
  }
  </code></pre>