Is it a bad idea to require modules globally and if so, is there a way to require modules across multiple project files without explicitly requiring them in each file?
I'm assuming the answers is "yes" to the first and "no" to the second but would like to confirm.
This is why I'm asking:
I'm working on a Node project in which there are a few modules(like mongoose) which I'm using in almost every file. I'd like to avoid explicitly requiring these in each file. The only solution I've come up with is to require modules globally (i.e. in my app.js file doing this: mongoose = require('mongoose'); instead of var mongoose = require('Mongoose');) but I'm assuming this is bad practice since declaring global variables is... bad.
Yes, globals are bad and the programming community at large has embraced avoidance of global variables as a sound practice. If you do this, everyone who ever looks at your code is going to do a massive facepalm immediately.
But yes, you can create globals just by omitting the var keyword as your example indicates.
Don't Repeat Yourself is about code, not about dependency declaration.