title: How to generate hash as a global variable using bcrypt and nodeJS
body: <p>I have a react component for signing into a single password web app. I have an <code>onChange={this.setState({password: event.target.value}}</code> prop on the input to update the password. Then when the user clicks the submit button it calls this function: </p>
  
  <pre><code> onSubmitSignIn = () =&gt; {
    fetch('http://localhost:3000/signin', {
      method: 'post',
      headers: {'Content-Type': 'application/json'},
      body: JSON.stringify({
        password: this.state.password
      })
    })
      .then(response =&gt; response.json())
      .then(response =&gt; {
        if (response === 'true') {
          this.props.onRouteChange('home');
        }
      })
  }
  </code></pre>
  
  <p>Here is what my server looks like: </p>
  
  <pre><code>const express = require('express')
  const app = express()
  const bcrypt = require('bcrypt-nodejs')
  var bodyParser = require('body-parser')
  var cors = require('cors')
  
  app.use(cors());
  app.use(bodyParser.json());
  app.get('/', (req, res) =&gt; res.send('Hello World!'))
  
  
  bcrypt.hash("password", null, null, function(err, hash) {
  console.log(hash)
  });
  
  app.post('/signin', (req, res) =&gt; {
  var a = JSON.parse(req.body);
    bcrypt.compare(a.password, hashNew, function(err, res) {
  if (hash === hashNew) {
      res.send(true);
  } else {
      res.send(false);
  }
  });
  })
  
  
  
  app.listen(3000, () =&gt; console.log('App listening on port 3000!'))
  </code></pre>
  
  <p>I am trying to make a hash using bcrypt as a global variable to compare to the hash that is created for the password the user has typed on submit. Thanks for any and all help. Please let me know if there is anything I need to clarify anything.</p>