title: How to send data from router to express handlebar template
body: <p>I'm having a hard time trying to get data retrieved from a postgres DB via router into a handlebar template.</p>
  
  <p>This is the folder structure:</p>
  
  <pre><code>-node_modules
  -public
  -routes
  --api
  ---db.js
  -views
  --layouts
  ---main.handlebars
  --index.handlebars
  -index.js
  </code></pre>
  
  <p>Here is an example request in the db.js file:</p>
  
  <pre><code>//get all users
  router.get("/", (req, res) =&gt; {
    db.result("SELECT * FROM users ORDER BY id")
      .then(data =&gt; {
        res.json(data.rows);
      })
      .catch(error =&gt; {
        return console.log("error");
      });
  });
  </code></pre>
  
  <p>And I want this data to be displayed into a template.</p>
  
  <p>This is the index.js file:</p>
  
  <pre><code>const users = require('./routes/api/db')
  
  const app = express();
  
  //init middleware
  app.use(logger);
  
  //handle bars middle
  app.engine('handlebars', exphbs({defaultLayout: 'main'}));
  app.set('view engine', 'handlebars');
  
  // body parser
  app.use(express.json());
  app.use(express.urlencoded({extended: false}));
  
  //render
  // app.get('/', users.getAllUsers);
  
  app.get('/displaydata', (req,res)=&gt; {
      res.render('index', {
          title: 'DATA',
  
  /* HOW DO I GET THE DATA TO BE DISPLAYED OVER HERE?*/
  
      });
  });
  
  //members api routes
  app.use('/api/db', users);
  </code></pre>