title: require function doesn't work inside a function within a method
body: <p>I'm using Node.js to build the back-end of an application and I'm using postgresql as database. I'm having problem with the implementation of the login. More precisely I am using the bcrypt module and it doesn't work in the function called by the execution of the query. Here is the code:</p>
  
  <pre><code>const login = async (request, response) =&gt; {
    const username = request.body.username
  
    console.log(request.body)
  
    pool.query('SELECT * FROM public."User" WHERE username = \'{' + username + '}\'', (error, results) =&gt; {
      if (error) {
        return response.status(400).send("Cannot find user: "+username)
      }
      try {
        if(await bcrypt.compare(request.body.password, results.rows[0].password.toString())) {
          response.send('Success')
        } else {
          response.send('Not allowed')
        }
      } catch {
        response.status(500).send("Server error")
      }
    })
  }
  </code></pre>
  
  <p>The problem is that I execute my query and it works, but when it arrives in the second if statement the problem is this:</p>
  
  <pre><code> if(await bcrypt.compare(request.body.password, results.rows[0].password.toString())) {
                 ^^^^^^
  
  SyntaxError: Unexpected identifier
  </code></pre>
  
  <p>I cannot figure out how to solve it.</p>