title: Call a function inside async function at a js class
body: <p>Hi I'm new at javascript programming.</p>
  
  <p>I have a node express project, I'm trying to create a login method inside my AuthenticationController class.</p>
  
  <p>My login method is like this right now:</p>
  
  <pre><code>const User = require('../models/User')
  
  class AuthenticationController {
  
    async login(req, res) {
      const { email, password } = req.body
      console.log('step 1')
      var hashPassword = await userPassword(email)
      console.log(hashPassword)
      console.log('step 2')
      return res.status(200).json({ 'msg': 'Log in OK!' })
  
    }
  
    userPassword(email) {
      User.findOne({ email: email }).exec(function(err, user) {
        if (err) return err
        else return user.password
      })
    }
  }
  </code></pre>
  
  <p>But I got an error saying that userPassword is undefined, I couldn't figure out why. So my doubts are: why this is happening, and how to do it correctly ?</p>
  
  <p>I also checked out this questions, but they didn't helped me:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/49982058/how-to-call-an-async-function">How to call an async function</a></li>
  <li><a href="https://stackoverflow.com/questions/47672661/async-function-inside-a-class">Async function inseide a class</a></li>
  </ul>
  
  <p>The error message at my console:</p>
  
  <p>(node:28968) UnhandledPromiseRejectionWarning: ReferenceError: userPassword is not defined
  ...</p>
  
  <p>(node:28968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)</p>
  
  <p>(node:28968) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.</p>