title: Cannot set property -hashed_password of null , of addFollower method in nodejs app
body: <p>My controller/user.js file has the following</p>
  <pre><code>exports.addFollower= (req,res )=&gt;{
      User.findByIdAndUpdate(req.body.followId, {
          $push:{followers: req.body.user_Id}
      },
               {new : true}
      )
      .populate('following', '_id name')
      .populate('followers', '_id name')
      .exec((err,result)=&gt;{
          if(err){
              return res.status(400).json({
                  error:&quot;This is an error &quot;
              })
          }
          result.hashed_password= undefined;
          result.salt = undefined;
          res.json(result)
   
      })
  }
  </code></pre>
  <p>And my routes/user.js file has the following</p>
  <p>const express = require('express');</p>
  <pre><code>const {userById ,allUsers, getUser,updateUser,deleteUser ,userPhoto
  , addFollowing,
  addFollower, removeFollowing, removeFollower
  }= require('../controllers/user');
  const {requireSignin} = require('../controllers/auth');
  
  const router = express.Router();
  
  router.put('/user/follow', requireSignin, addFollowing,addFollower );
  router.put('/user/unfollow', requireSignin, removeFollowing, removeFollower);
  </code></pre>
  <p>User Model is as follows</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  let uuidv1 = require('uuidv1');
  const crypto = require('crypto');
  const {ObjectId} = mongoose.Schema;
  
  const userSchema = new mongoose.Schema({
      name:{
          type:String,
          trim:true,
          required:true
      },
      email:{
          type:String,
          trim:true,
          required:true
  
      },
      hashed_password:{
          type:String,
          required: true
      },
      salt: String,
      created:{
          type:Date,
          default:Date.now
      },
      updated:Date,
      photo:{
          data:Buffer,
          contentType:String
      },
      about:{
          type:String,
          trim:true
      },
      following:[{type:ObjectId , ref:&quot;User&quot;}],
      followers:[{type:ObjectId, ref:&quot;User&quot;}]
  
  });
  
  
  
  //virtual field
  userSchema.virtual('password')
  .set(function(password){
      //create a temporary variable called _password
      this._password =password
      //generate a timestamp 
      this.salt = uuidv1();   
      //encrypt password
      this.hashed_password= this.encryptPassword(password);   
  })
  .get(function(){
      return this._password
  })
  
  //methods
  userSchema.methods = {
  
     authenticate:function(plainText){
  
       return this.encryptPassword(plainText) === this.hashed_password
  
     },
  
      encryptPassword:function (password){
          if(!password)   
          return &quot;user SCHEMA error&quot;;
          
          try{
              return crypto.createHmac('sha1', this.salt)
              .update(password)
              .digest('hex');
               
          }
          catch(err) {
  
              return &quot;userSchema error 2  &quot;;
  
  
          }
      }
  }
  
  
  module.exports= mongoose.model(&quot;User&quot;,userSchema)
  </code></pre>
  <p>But when I hit the following Route /user/follow with valid token i get the following error</p>
  <p>TypeError: Cannot set property 'hashed_password' of null
  at rfs\nodeapi\controllers\user.js:180:31</p>
  <p>line 180 refers to this section</p>
  <pre><code>exports.addFollower= (req,res )=&gt;{
      User.findByIdAndUpdate(req.body.followId, {
          $push:{followers: req.body.user_Id}
      },
               {new : true}
      )
      .populate('following', '_id name')
      .populate('followers', '_id name')
      .exec((err,result)=&gt;{
          if(err){
              return res.status(400).json({
                  error:&quot;This is an error &quot;
              })
          }
          result.hashed_password= undefined;
          result.salt = undefined;
          res.json(result)
  
  
      })
  
  }
  </code></pre>
  <p>How do I debug this?</p>
  <p>Thanks for the help! :)</p>