title: DELETE not working as expected in Express/Postgres
body: <p>I have created a Kanban board using JS without a framework on the FE. On the backend, I am using Express/Postgres.</p>
  
  <p>My issue is with my 'Delete' operation not working. All other CRUD ops are fine.  </p>
  
  <p>When I use the app to try and delete a 'plan', the request returns a status '200' code but the entry does not actually get deleted. </p>
  
  <p>My code is below -</p>
  
  <p>Queries.js</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const Pool = require('pg').Pool;
  const pool = new Pool({
   user: 'kanban',
   host: 'localhost',
   database: 'kanbandb',
   password: 'k4nb4n.d3',
   port: 5432
  });
  
  const getPlans = (request, response) =&gt; {
   pool.query(
    'SELECT * FROM plans ORDER BY project_id ASC',
    (error, results) =&gt; {
     if (error) {
      throw error;
     }
     response.status(200).json(results.rows);
    }
   );
  };
  
  const getPlanById = (request, response) =&gt; {
   const id = parseInt(request.params.id);
  
   pool.query('SELECT * FROM plans WHERE id = $1', [id], (error, results) =&gt; {
    if (error) {
     throw error;
    }
    response.status(200).json(results.rows);
   });
  };
  
  const createPlan = (request, response) =&gt; {
   console.log(request.body);
   const planID = request.body.planID;
   const planName = request.body.planName;
   // const barColor = request.body.barColor;
   const checkbox_state = true;
   pool.query(
    'INSERT INTO plans (plan_id, plan_name, checkbox_state) VALUES ($1, $2, $3)',
    [planID, planName, checkbox_state],
    (error, results) =&gt; {
     if (error) {
      throw error;
     }
     console.log(results);
     response.status(201).send(`Plan added with ID: ${results.insertId}`);
    }
   );
  };
  
  const updatePlan = (request, response) =&gt; {
   //const id = parseInt(request.params.id);
   const { planID, planName, barColor, checkbox_state } = request.body;
  
   pool.query(
    'UPDATE plans SET plan_name = $1, plan_id = $2 WHERE id = $3',
    [planID, planName, barColor, checkbox_state],
    (error, results) =&gt; {
     if (error) {
      throw error;
     }
     response.status(200).send(`Plan modified with ID: ${id}`);
    }
   );
  };
  
  const deletePlan = (request, response) =&gt; {
   console.log(request.body);
   const planName = request.body.planName;
  
   pool.query(
    'DELETE FROM plans WHERE plan_name = $1',
    [planName],
    (error, results) =&gt; {
     if (error) {
      throw error;
     }
     console.log(results);
     response.status(200).send(`Plan deleted with Name: ${results}`);
    }
   );
  };
  
  module.exports = {
   getPlans,
   createPlan,
   updatePlan,
   deletePlan
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>index.js: </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>const express = require('express');
  // const methodOverride = require('method-override');
  const https = require('https');
  const fs = require('fs');
  const bodyParser = require('body-parser');
  const app = express();
  const db = require('./queries');
  const port = 3000;
  const cors = require('cors');
  
  // var server = express();
  var urlencodedParser = bodyParser.urlencoded({ extended: true });
  
  // override with POST having ?_method=DELETE
  // app.use(methodOverride('_method'));
  app.use(cors());
  app.use(bodyParser.json());
  app.use(
   bodyParser.urlencoded({
    extended: true
   })
  );
  
  app.options('*', cors()); // include before other routes
  
  app.get('/', (request, response) =&gt; {
   response.json({ info: 'Node.js, Express, and Postgres API' });
  });
  
  app.get('/plans', db.getPlans);
  //app.get("/plans/:id", db.getPlanById);
  app.post('/plans', urlencodedParser, db.createPlan);
  
  app.post('/testpost', urlencodedParser, function(req, res) {
   console.log(req.body);
  });
  app.put('/plans/:id', db.updatePlan);
  
  app.delete('/plans/:planName', urlencodedParser, db.deletePlan);
  // console.log(req.body);
  
  app.listen(port, () =&gt; console.log(`Example app listening on port ${port}!`));</code></pre>
  </div>
  </div>
  </p>
  
  <p>the my server returns this:</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>Example app listening on port 3000!{}
  Result {
    command: 'DELETE',
    rowCount: 0,
    oid: null,
    rows: [],
    fields: [],
    _parsers: [],
    _types: TypeOverrides {
      _types: {
        getTypeParser: [Function: getTypeParser],
        setTypeParser: [Function: setTypeParser],
        arrayParser: [Object]
      },
      text: {},
      binary: {}
    },
    RowCtor: null,
    rowAsArray: false
  } {
    id: '5',
    plan_name: 'hello world',
    plan_id: 'ssss'
  }
  Result {
    command: 'DELETE',
    rowCount: 0,
    oid: null,
    rows: [],
    fields: [],
    _parsers: [],
    _types: TypeOverrides {
      _types: {
        getTypeParser: [Function: getTypeParser],
        setTypeParser: [Function: setTypeParser],
        arrayParser: [Object]
      },
      text: {},
      binary: {}
    },
    RowCtor: null,
    rowAsArray: false
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>If I try the same with Postman, I get :</p>
  
  <p>'Plan deleted with ID: [object Object]'</p>
  
  <p>The error thown on the screen from the request when done in the app is in this screenshot.</p>
  
  <p><a href="https://i.stack.imgur.com/dS6D5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dS6D5.png" alt="error message"></a></p>
  
  <p>This is what I have in my JS on the front end: </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>// ************ Delete User ************
  function deletePlan(event) {
    event.preventDefault();
    // Pop up a confirmation dialog
    let confirmation = confirm('Are you sure you want to delete this plan?');
  
    // Check and make sure the user confirmed
    if (confirmation === true) {
      // If they did, do our delete
      $.ajax({
        type: 'DELETE',
        url: 'http://blusrv019.blue.works:3000/plans/' + planName
      }).done(function(response) {
        // Check for a successful (blank) response
        if (response.msg === '') {} else {
          alert('Error: ' + response.msg);
        }
      });
    } else {
      // If they said no to the confirm, do nothing
      return false;
    }
  }
  
  // ********* Delete User btn click *********
  $('#deletePlanBtn').on('click', deletePlan);</code></pre>
  </div>
  </div>
  </p>
  
  <p>I feel like I am missing some thing really stupid but havn't been able to figure it out. </p>
  
  <p>Can anyone provide some wisdom? I have been searching the WWW all day and not found a similar situation or solution and have changed my code around in so many ways that I have lost track. </p>
  
  <p>Any advice is appreciated. Also sorry if my post is not appropriate or structured correct (I'm still a newb).</p>