title: How can I connect express js with phpmyadmin (xampp vm os x)?
body: <p>I had install xampp vm on os x</p>
  
  <p>The view of xampp like this :</p>
  
  <p><a href="https://i.stack.imgur.com/2T7Kg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2T7Kg.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Ky4A1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ky4A1.png" alt="enter image description here"></a></p>
  
  <p>I access phpmydmin like this :</p>
  
  <p><a href="https://i.stack.imgur.com/E9yZW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E9yZW.png" alt="enter image description here"></a></p>
  
  <p>I want to connect it with my project express js</p>
  
  <p>I try like this :</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const bodyParser = require("body-parser");
  const request = require("request");
  const https = require('https');
  const mysql = require('mysql');
  
  //create database connection
  const conn = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'myappexpress',
    port: '8080'
  });
  
  //connect to database
  conn.connect((err) =&gt;{
    if(err) throw err;
    console.log('Mysql Connected...');
  });
  
  const app = express();
  app.use(bodyParser.json());
  
  // Add headers
  app.use(function (req, res, next) {
  
      // Website you wish to allow to connect
      res.setHeader('Access-Control-Allow-Origin', '*');
  
      // Request methods you wish to allow
      res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
  
      // Request headers you wish to allow
      res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
  
      // Set to true if you need the website to include cookies in the requests sent
      // to the API (e.g. in case you use sessions)
      res.setHeader('Access-Control-Allow-Credentials', true);
  
      // Pass to next layer of middleware
      next();
  });
  
  //show all customers
  app.get('/api/customers',(req, res) =&gt; {
    let sql = "SELECT * FROM customers";
    let query = conn.query(sql, (err, results) =&gt; {
      if(err) throw err;
      res.send(JSON.stringify({"status": 200, "error": null, "response": results}));
    });
  });
  
  // Set static folder
  app.use(express.static(path.join(__dirname, 'public')));
  
  const PORT = process.env.PORT || 5000;
  
  app.listen(PORT, () =&gt; console.log(`Server started on port ${PORT}`));
  </code></pre>
  
  <p>Then I call <a href="http://localhost:5000/api/customers" rel="nofollow noreferrer">http://localhost:5000/api/customers</a> from postman</p>
  
  <p>On the command prompt exist error like this :</p>
  
  <p><a href="https://i.stack.imgur.com/gqFPb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gqFPb.png" alt="enter image description here"></a></p>
  
  <p>How can I solve this problem?</p>