title: Node.js CORS error
body: <p>I am using Node as backend server and Angular 4 as frontend. I am trying to send the result of query through soap protocol. The function works fine but with CORS PLUGIN installed in the browser.But how can I solve it without those plugins.</p>
  
  <p>I have searched for some solutions and I have installed CORS package in my node file and also did the following things to my server.js file.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//## =======BASE SETUP=======
  
  const arangojs = require('arangojs');
  const express = require('express');
  const aqlQuery = arangojs.aqlQuery;
  const bodyParser = require('body-parser');
  
  var cors = require('cors');
  var app = express();
  app.use(cors());
  app.use(function(req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>But it didn't help. The error is still there.How can I solve this error.I have posted my server side code following:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var soap = require('strong-soap').soap;
  var http = require('http');
  var fs = require('fs');
  
  function dbQuery() {
    var response = db.query(aqlQuery `
                   LET startVertex = (FOR doc IN spec
                   FILTER doc.serial_no == '"123456abcde"'
                   LIMIT 2
                   RETURN doc
                   )[0]
  
                  FOR v IN 1 ANY startVertex belongs_to
                  RETURN v.ip`, {
      bindVar1: 'value',
      bindVar2: 'value',
    });
    console.log("response is " + response);
    return response;
  
  }
  
  function main2() {
    var result2 = dbQuery();
  
    return result2.then(function(test) {
  
      console.log("test is " + JSON.stringify(test._result));
      var IP = test._result.filter(Boolean);
      console.log("Ip is " + IP);
  
      var xml = require('fs').readFileSync('check_username.wsdl', 'utf8');
      var soap_msg = '&lt;soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:examples:CheckUserNameService"$
      '&lt;soapenv:Header/&gt;' + '&lt;soapenv:Body&gt;' + '&lt;urn:CheckUserNameResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;' + '&lt;status xsi:type="xsd:string"&gt;' + JSON.stringify(test._result) + '&lt;/status&gt;' + '&lt;/urn:CheckUserNameResponse&gt;' +
        '&lt;/soapenv:Envelope&gt;';
  
      var server = http.createServer(function(request, response) {
        response.end(soap_msg);
      });
  
      var port = 8000;
      server.listen(port);
      var soapServer = soap.listen(server, '/test', xml);
      console.log('SOAP service listening on port ' + port);
    });
  }
  main2();</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Error</strong></p>
  
  <ul>
  <li>Failed to load <a href="http://192.168.72.234:8000/serverfile.js" rel="noreferrer">http://192.168.72.234:8000/serverfile.js</a></li>
  <li>Response to preflight request doesn't pass access control check: No
  'Access-Control-Allow-Origin' header is present on the requested
  resource</li>
  <li>Origin '<a href="http://192.168.72.275:4555" rel="noreferrer">http://192.168.72.275:4555</a>' is therefore not allowed access.</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/PFvsL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PFvsL.png" alt="enter image description here"></a></p>