title: Get cross origin resource in nodejs from php
body: <p>Suppose there are two servers serv1 &amp; serv2. i am trying to get xmlhttprequest from a php in serv1 in a node server in serv2. My code looks like:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var cors = require('cors');
  var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
  app.use(function(req, res, next) {
      res.setHeader('Access-Control-Allow-Origin', 'serv1');
      res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
      res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
      res.setHeader('Access-Control-Allow-Credentials', true);
      next();
  });
  app.use(cors());
  app.get('/session', function(req, res) {
      var u = "serv2/somephp.php";
      var xhr = new XMLHttpRequest();
      xhr.open("GET", u, true);
      xhr.withCredentials = true;
      xhr.onload = function() {
          console.log(xhr.responseText);
      };
      xhr.send();
  })
  app.listen(8165, function() {
      console.log('Express File Uploading server listening on port 8165');
  })
  </code></pre>