title: Connect node.js PostgreSQL database and Vue client locally
body: <p>New to all of this so this might be the wrong setup. I have set up one project which uses node to connect to a postgreSQL. This works and I can start this from VS Code using:</p>
  <pre><code>node index.js
  </code></pre>
  <p>and the response is:</p>
  <pre><code>App running on port 3000.
  </code></pre>
  <p>Another project is a client and has been created Vue. This is started using</p>
  <pre><code>npm run serve
  </code></pre>
  <p>The response is:</p>
  <pre><code>App running at:
    - Local:   http://localhost:8080/
  </code></pre>
  <p>The Vue client gets data from a source using the code below and then displays it. In this example it uses some dummy data and works fine.</p>
  <pre><code>created: function () {
      axios
          .get('https://jsonplaceholder.typicode.com/users/')
          .then(res =&gt; {
              this.users = res.data;
          })
  }
  </code></pre>
  <p>However if I change the source above to communicate with the local postgreSQL database server:</p>
  <pre><code>.get('http://localhost:3000/users/')    
  </code></pre>
  <p>I quite rightly get the security issue in the browser console when trying to connect:</p>
  <blockquote>
  <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading
  the remote resource at http://localhost:3000/users/. (Reason: CORS
  header 'Access-Control-Allow-Origin' missing)</p>
  </blockquote>
  <p>So how do I intergrate the node.js part and the vue client part?</p>
  <p>UPDATE</p>
  <p>The answer to the question is below but I changed very slightly. The following was added to the index.js file (the node postgreSQL part). It is importing cors and saying allow conneciton from localhost:8080. Works perfectly:</p>
  <pre><code>import cors from 'cors';
  
  const corsOptions = {
     origin: 'http://localhost:8080'
  };
  </code></pre>