James P. Wright
James P. Wright

Reputation: 9131

Node.js and Mongoose, too slow to put Schema definitions in separate files?

Playing around with Node.js and I really want to keep my file structure organized. Normally in a project in another language I would have a structure like this:

The (potential) problem I see is this: I use Mongoose and MongoDB for my database, in order to define a "Model" I need a Mongoose Schema, in order to do that I have to connect to the database with Mongoose in each of the Controllers and Model files.

I know so little about these technologies, this could be lightning quick and never be an issue and I wouldn't have a clue. Or is this something I should avoid and just shove everything in one (very large) file?

Upvotes: 4

Views: 1224

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146154

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

Upvotes: 5

Related Questions