I am trying to create a file that will contain some functions that will be used throughout the entire project. I would like these functions to have access to all the modules that I am using in the project(which is why I don't want to use another module)
in my app.js I can use require to a static folder containing the js file and it works fine however if I go to routes/index.js and try to require the same folder it cannot find it.
Im guessing thats because its not leaving the routes folder. How can I move to the parent of the routes folder.
I have tried
require('controllers/cf');
require('./controllers/cf');
require('cf')
require('../controllers/cf');
require('../~path to project~/controllers/cf');
none of these work. I know this is simple however the solutions I have found dont work unless I make a node module then it has no problems but then other modules are not within my scope
This will work.
var path = require('path');
require(path.join(__dirname, '../controllers/cf'));