title: Node.js res.setHeader('content-type', 'text/javascript'); pushing the response javascript as file download
body: <p><strong>Scenario</strong>: Consider the following code to give a JavaScript as a response from the Node.JS server.</p>
  <pre><code>var http = require('http');
  
  http.createServer(function (req, res) {
  var JS_Script = 'function Test() { alert(&quot;test success&quot;)}';
  res.setHeader('content-type', 'text/javascript');
  res.send(JS_Script);
  }).listen(8811);
  </code></pre>
  <p><strong>Issue</strong>: It forcing the browser to download the file.</p>
  <p><strong>Question</strong>: How can I make it to render on browser?</p>
  <p><strong>Note</strong>: Working in .net web service with same <code> HTTP-header: 'content-type', 'text/javascript'</code></p>
  <p>So, Its clear following statement does not hold good.<br>
  If you want a web browser to render the HTML, you should change this to:</p>
  <pre><code>Content-Type: text/html
  </code></pre>
  <p><strong>Update</strong>: On inspecting the <code>content-type</code> during the download its <code>application/octet-stream</code></p>
  <p>But the same when I hit a request with curl, the following is the output:</p>
  <pre><code>C:\&gt;curl -is http://localhost:8811/
  HTTP/1.1 200 OK
  Content-Type: text/javascript
  Content-Length: 166
  Date: Tue, 09 Apr 2013 10:31:32 GMT
  Connection: keep-alive
  
  function Test() { alert(&quot;test success&quot;)}
  </code></pre>