Search code examples
javascriptnode.jsmodel-view-controllercontrollerdirectory-structure

MVC Controllers in a Node application, are these controllers?


I'm writing a web crawler in Node. It will crawl my various bank accounts and provide me with a summary of my finances. Acknowledging the security issues around this, i'm just doing it as a proof of concept.

I'm having a problem with structuring my application.

So far my controller modules are:

  • /controllers/routes.js (contains express routes)
  • /controllers/configure.js (takes values from /settings.js and interprets them for /app.js)
  • /controllers/crawler.js (downloads a page, traverses DOM and outputs values from selectors)
  • /controllers/login.js (provides crawler.js with functions to log in to bank accounts)

Are these valid controller modules, or are they more suited for a directory such as /lib/?

At the end of the day it doesn't matter for the functionality of the project, but I'm presenting it at the end of the week.


Solution

  • Controllers are the things, which process requests by glueing models and views. The router routes a request to a controller, this one calls methods of models in order to render a view.
    Since most of your code is just code to fulfill some specific tasks, which have nothing to do with the frontend code of your application: No, most of the code is nothing I would call controller code.

    As you already said it makes more sense to group that into modules and put it in other directories. These functions are either called by the controllers, to render the frontend, or (more likely) are called via cronjobs to update the database.