title: Angular 6 - No 'Access-Control-Allow-Origin' header is present on the requested resource
body: <p>I have an Angular 6 project, which has a service with is pointing to a server.js</p>
  
  <pre><code>Angular is on port: 4200 and Server.js is on port: 3000.
  </code></pre>
  
  <p>When I point the service to <code>http://localhost:3000/api/posts</code> (Server.js location), I'm getting this error:</p>
  
  <pre><code>Failed to load http://localhost:3000/api/posts: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
  </code></pre>
  
  <p>Here is the server.js code:</p>
  
  <pre><code>// Get dependencies
  const express = require('express');
  const path = require('path');
  const http = require('http');
  const bodyParser = require('body-parser');
  
  // Get our API routes
  const api = require('./server/routes/api');
  
  const app = express();
  
  // Parsers for POST data
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  // Point static path to dist
  app.use(express.static(path.join(__dirname, 'dist')));
  
  // Set our api routes
  app.use('/api', api);
  
  // Catch all other routes and return the index file
  app.get('*', (req, res) =&gt; {
    res.sendFile(path.join(__dirname, 'dist/myproject/index.html'));
  });
  
  /**
   * Get port from environment and store in Express.
   */
  const port = process.env.PORT || '3000';
  app.set('port', port);
  
  /**
   * Create HTTP server.
   */
  const server = http.createServer(app);
  
  /**
   * Listen on provided port, on all network interfaces.
   */
  server.listen(port, () =&gt; console.log(`API running on localhost:${port}`));
  </code></pre>
  
  <p>My question is:</p>
  
  <p>How to I get server.js to allow this call?</p>