title: Question about Model in MVC architecture in web app using NodeJs and MySQL
body: <p>I am new to NodeJs and I am trying to create a web application using express framework and MySql. I get that in MVC architecture the views are for example the *.ejs files. The controllers are supposed to have the logic and the models should focus on the database.</p>
  
  <p>But still I am not quite sure what is supposed to be inside the model. I have the following code in my controller (probably wrong, not following mvc design):</p>
  
  
  
  <pre><code>const mysql = require('mysql');
  const db = mysql.createConnection(config);
  db.query(query, (err, result) =&gt; {
      if (err) {
          return res.redirect('/');
      }
      res.render('index.ejs', {
          users: result
      });
  });
  </code></pre>
  
  <p>Now from what I've read the controller should ask the model to execute the query to the database, get the results and render the view (index.ejs'). </p>
  
  <p>My question is this: What should be inside the model.js file? Can I make something like this?</p>
  
  <p>controller.js</p>
  
  <pre><code>const db = require('./models/model.js');
  db.connect();
  const results = db.query(query);
  if(results != null) {
       res.render('index.ejs'){
            users: result
       });
  }
  </code></pre>
  
  <p>model.js will make a query to mysql handle any errors and return the result. </p>
  
  <p>From what I've read I have two options. Option1: pass callback function to model and let the model render the view (I think that's wrong, model should not communicate with view, or not?) Option2: possible use of async/await and wait for model to return the results but I am not sure if this is possible or how.</p>