Is Node.js and Mongoose too slow to put schema definitions in separate files?

Playing with Node.js, and I really want my file structure to be organized. Usually in a project in another language I would have this structure:

  • Node Application Catalog
    • App.js
    • Controllers
      • UserController.js
      • OtherController.js
    • Models
      • UserModel.js
      • OtherModel.js

The problem (potential) that I see is this: I use Mongoose and MongoDB for my database to define a "model". I need a Mongoose schema to do this, I have to connect to the database using Mongoose in each of the controller files and models.

I know so little about these technologies, it can be lightning fast and will never be a problem, and I would have no idea. Or is this something I should avoid and just put everything in one (very large) file?

+4
source share
1 answer

You do not need to connect to mongo in every controller / model file. Just do it once in App.js and you App.js done.

+5
source

All Articles