I have an express project where I have a directory structure like so,
Now let's say from my routes I want to require the component toolbar I do it like this
toolbar = require(__dirname + '/../components/toolbar')
Now when I run my test for routes I need to require routes. When I do this I get an error at runtime that toolbar file could not be found.
Is there some global available like say __express_home that I could use in my require so that I would not run into this issue? I would then use it as so,
toolbar = require(__express_home + '/components/toolbar')
You can just do:
toolbar = require('../components/toolbar')
Here is an example from express's github repo.
var express = require('../..') , app = express() , site = require('./site') , post = require('./post') , user = require('./user');
This recipe can be found in it's original form on Stack Over Flow.