title: How to combine schema model with file upload in Node.js and MongoDB?
body: <p>Good day everyone, I am building a web application to store employee information in a local database. I have written the necessary code so that the client can input the required information such as Name, email, phone number etc. via a form and save it to MongoDB. Now I would like to add a file upload feature so that documents can be uploaded alongside employee information, such as insurance policies, passport copies etc. I am struggling to find a way to implement this as a lot methods online show implementations of CRUD and file uploads separately. Is there anyone experienced who would be able to suggest an implementation approach? I'm new to Node dev and not familiar with the vast selection of available frameworks. So far I have the following set up:</p>
  
  <p><strong>Frameworks used:</strong> Express, Mongoose, Express-Handlebars (view engine), Bootstrap</p>
  
  <p><strong>employee.Model:</strong> </p>
  
  <pre><code>const mongoose = require('mongoose');
  const mongoURI = 'mongodb://localhost:27017/testDB'
  const conn = mongoose.createConnection(mongoURI, {useNewUrlParser: true});
  
  
  Schema = mongoose.Schema;
  var employeeSchema = new Schema({
      fullName: {
          type: String,
          required: true
      },
      email: {
          type: String
      },
      mobile: {
          type: String
      },
      city: {
          type: String
      }
      });
  
  const Employee = conn.model('Employee', employeeSchema);
  module.exports = Employee;
  </code></pre>
  
  <p><strong>Employee Controller:</strong></p>
  
  <pre><code>const mongoose = require ('mongoose');
  const express = require ('express');
  var router = express.Router();
  const Employee = require('../models/employee.model');
  
  router.post('/', (req, res) =&gt; {
      insertRecord(req, res);
  });
  
  function insertRecord (req, res) {
  var employee = new Employee();
  employee.fullName = req.body.fullName;
  employee.email = req.body.email;
  employee.mobile = req.body.mobile;
  employee.city = req.body.city;
  employee.save((err, doc) =&gt;{
      if (!err)
          res.redirect('employee/list');
      else {
          console.log('Error during record insertion: ' + err);
      }
  });
  }
  </code></pre>
  
  <p><strong>Handlebars View:</strong></p>
  
  <pre><code>&lt;h3&gt;{{viewTitle}}&lt;/h3&gt;
  
  &lt;form action="/employee" method="POST" autocomplete="off"&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Full Name&lt;/label&gt;
          &lt;input type="text" class="form-control" name="fullName" 
  placeholder="Full Name"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Email&lt;/label&gt;
          &lt;input type="text" class="form-control" name="email" 
  placeholder="Email"&gt;
      &lt;/div&gt;
      &lt;div class="form-row"&gt;
          &lt;div class="form-group col-md-6"&gt;
              &lt;label&gt;Mobile&lt;/label&gt;
              &lt;input type="text" class="form-control" name="mobile" 
  placeholder="Mobile"&gt;
          &lt;/div&gt;
          &lt;div class="form-group col-md-6"&gt;
              &lt;label&gt;City&lt;/label&gt;
              &lt;input type="text" class="form-control" name="city" 
  placeholder="City"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;button type="submit" class="btn btn-info"&gt;&lt;i class="fa fa- 
  database"&gt;&lt;/i&gt; Submit&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>