title: Receiving net::ERR_EMPTY_RESPONSE with Nodejs Post Request
body: <p>I'm trying to make a post request in my Node app; however, I am getting the following error. </p>
  
  <pre><code>OPTIONS http://localhost:27017/postDebate net::ERR_EMPTY_RESPONSE
  </code></pre>
  
  <p>How to resolve this? </p>
  
  <p>Here is my route:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var Debate = require('../models/debate');
  var mdb = require('mongodb').MongoClient,
    ObjectId = require('mongodb').ObjectID,
    assert = require('assert');
  var api_version = '1';
  var url = 'mongodb://localhost:27017/debate';
  
  router.post('/'+api_version+'/postDebate', function(req, res, next) {
    var debate = new Debate(req.body);
    console.log(debate, "here is the debate");
    debate.save(function(err) {
      if (err) throw err;
      console.log('Debate saved successfully!');
    });
    res.json(debate);
  });
  
  module.exports = router;
  </code></pre>
  
  <p>And since I am invoking this route after onclick calling a function in my ejs file, here is my javascript file. </p>
  
  <pre><code>function postDebate() {
    var topic = document.getElementById('topic').value;
    var tags = document.getElementById('tags').value;
    var argument = document.getElementById('argument').value;
  
    var debateObject = {
      "topic": topic,
      "tags": tags,
      "argument": argument
    };
    console.log(topic, tags, argument);
  
    $.ajax({
      type: 'POST',
      data: JSON.stringify(debateObject),
      contentType: "application/json",
          //contentType: "application/x-www-form-urlencoded",
          dataType:'json',
          url: 'http://localhost:27017/post',                      
          success: function(data) {
            console.log(JSON.stringify(data), "This is the debateObject");                               
          },
          error: function(error) {
            console.log(error);
          }
        });
  }
  </code></pre>
  
  <p><strong>How do I resolve this error? What is the problem here?</strong></p>
  
  <pre><code>OPTIONS http://localhost:27017/postDebate net::ERR_EMPTY_RESPONSE
  </code></pre>