title: TypeError: Cannot read property 'code' of null
body: <p>I am registering my user, in the mongo DB. I am creating an instance of the data in the form and calling .save() method of mongoose. However, my app crashes (Although users are getting saved in the database perfectly):-</p>
  
  <p>Initially, I thought that I am not saving "confirm password" in the instance so that may be creating an error but even after commenting that part of the code problem still persists.</p>
  
  <p>I have not created anything by the name of <strong>code</strong> in my files.</p>
  
  <p><strong>Following is my error</strong></p>
  
  <pre><code>Error:-
  events.js:298
        throw er; // Unhandled 'error' event
  
  TypeError: Cannot read property 'code' of null
  </code></pre>
  
  <p><strong>This is my post request:-</strong></p>
  
  <pre><code>router.post("/signup", function(req,res){
  let registered_user=new User(req.body);
  registered_user.save(function(err, doc){
      if(err){
          console.log("Something went Wrong");
      }
      if(err.code===11000){
          console.log("User with same details already registed");
      }
  });
  res.redirect("/");
  });
  </code></pre>
  
  <p><strong>This is my HTML Form:-</strong></p>
  
  <pre><code>&lt;form action="/signup" method="POST"&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;&lt;strong&gt;Enrollment Number&lt;/strong&gt;
              &lt;br&gt; 
          &lt;input class="form-control" type="text" name="EnrollNumber" placeholder="Enrollment Number" required&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;&lt;strong&gt;Email:-&lt;/strong&gt;
              &lt;br&gt; 
          &lt;input class="form-control" type="email" name="Email" placeholder="Email" required&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;&lt;strong&gt;Name&lt;/strong&gt;
              &lt;br&gt;
          &lt;input class="form-control" type="text" name="Name" placeholder="Name" required&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;&lt;strong&gt;Department&lt;/strong&gt; 
          &lt;select id="" name="Department" required&gt;
              (...)
            &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;&lt;strong&gt;Position&lt;/strong&gt; 
          &lt;select id="" name="Role" required&gt;
              &lt;option value="Student"&gt;Student &lt;/option&gt;
              ...(Some more)
            &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;&lt;strong&gt;Gender&lt;/strong&gt; 
          &lt;select id="" name="Gender" required&gt;
              (...)
            &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
      &lt;label&gt;&lt;strong&gt;password :&lt;/strong&gt;&lt;br&gt;
          &lt;input name="password" id="password" type="password" onkeyup='check();'&gt;
        &lt;/label&gt;
        &lt;br&gt;
        &lt;label&gt;&lt;strong&gt;Confirm Password:&lt;/strong&gt;
          &lt;br&gt; 
          &lt;input type="password" id="confirm_password" onkeyup='check();'&gt; 
          &lt;span id='message'&gt;&lt;/span&gt;
        &lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;button class="btn btn-lg btn-info btn-block"&gt;Submit!&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>And My User Schema</strong></p>
  
  <pre><code>var UserSchema=new mongoose.Schema({
  Name: {
      type:String,
      required: true
  },
  Email: {
      type:String,
      required: true,
      unique: true
  },
  Role: {
      type:String,
      required: true
  },
  EnrollNumber: {
      type:Number,
      required: true,
      unique: true
  },
  password: {
      type:String,
      required: true
  },
  Department: {
      type:String,
      required: true
  },
  Gender: {
      type:String,
      required: true
  }
  });
  </code></pre>