title: making routes in node js with MVC
body: <p>I am new to backend programming and I am trying to route my application which is built on nodejs and expressjs but. I first built it without using the 'Router()' in express but now am trying to integrate it together with MVC and I am encountering some issues.</p>
  <p>This is a snippet of the code that is supposed to route to /storePost:</p>
  <p>.... in the index.js file:</p>
  <pre><code>var express = require('express');
  
  ...
  
  var adminRouter = require('./routes/admin');
  var indexRouter = require('./routes/index');
  
  app.use('/admin', adminRouter);
  app.use('/', indexRouter);
  
  ...
  </code></pre>
  <p>...in the admin.js file:</p>
  <pre><code>var express = require('express');
  var router = express.Router();
  ...
  
  var bookController = require('../controllers/bookController');
  
  ...
  
  router.get('/createBook', bookController.book_create);
  router.post('/storeBook' , bookController.book_store);
  
  ...
  module.exports = router
  </code></pre>
  <p>...in the bookController.js file</p>
  <pre><code>var Book = require('../database/models/Book');
  ...
  
  var book_store = (req, res) =&gt; {
      try{
          var { file } = req.files;
         
          file.mv(path.resolve(__dirname,'public/uploads', file.name), (error) =&gt; {
              console.log('File loaded to server');
          
              Book.create({
                  ...req.body,
                  file: `/books/${file.name}`
              }, (error) =&gt; {
                          console.log(error);
                          res.redirect('/displayBook');
                      });
          });   
      }catch(error) {
          console.log(error);
      }
  };
  
  ...
  
  module.exports = {
     ...
     book_store: book_store,
     ...
  }
  
  </code></pre>
  <p>And this is the few the application is supposed to route from:</p>
  <pre><code>@layout('layouts.admin');
  
  @section('content')
  
  &lt;div class=&quot;container p-2 m-4&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-8-md offset-2&quot;&gt;
              &lt;form class=&quot;form-signin&quot; method=&quot;POST&quot; action=&quot;/storeBook&quot; enctype=&quot;multipart/form-data&quot;&gt;
                  ...
                  &lt;button class=&quot;btn btn-primary btn-round&quot; type=&quot;submit&quot;&gt;Create Book&lt;/button&gt;
                &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;style&gt;
  
  &lt;/style&gt;
  &lt;br&gt;
  &lt;br&gt;
  @endsection
  </code></pre>
  <p>The app is running on MongoDB/mongoose for the database.
  Here is the error the application is throwing: Cannot Post /storeBook.</p>