Sunday, 3 April 2016

better way to do Express/Node "Require"? (noob-ish question)

Basically, i have my app laid out like this:src/ models/ routes/ index.js my routes are written like your basic routes:router.get() router.post() module.exports = router my index keeps all my routes:var x = require ('./routes/routefile-N'); app.use('/path', x); my issue is when i want to use models in routes, i am forced to use abs pathsvar model = require('../models/model-fileN'); which means, if i want to modify my dir structure, so that there is now another dir in both routes and models:src/ models/ users/ blogs/ routes/ users/ wiki/ and i am adding blog models from wiki routes, my require would look like:var model = require('../../models/blogs/model-file'); is there a way to register models/routes "globally" ish so that when you "require" you dont need path?

Submitted April 03, 2016 at 06:12PM by T-rex_with_a_gun

No comments:

Post a Comment