I am trying to require a file relatively and mysteriously the following is happening
This works well which points to /Users/marcos/Desktop/Taper/lib/utils.js
myPath = "/Users/marcos/Desktop/Taper/lib/./utils";
require(myPath);
This doesn't but it should point to exactly the same file:
require.paths.unshift("/Users/marcos/Desktop/Taper/lib")
require("./utils"); //Doesn't work with './'
require("utils"); //Works Fine
Anyone knows why I can't still use ./
in this case for loading the path since
require("path").resolve("/Users/marcos/Desktop/Taper/lib", "./utils")
results in:
"/Users/marcos/Desktop/Taper/lib/utils"
anyway?
Thanks in advance
You can pass that using
NODE_PATH
Example:
i created a new node module called "rekuire"
it allows you to "require" without using of relative paths
its a big time saver when it comes to testing/refactoring
super easy to use
UPDATED:
From the documentation:
Here’s the original answer, which refers to
require.paths
(which is no longer supported):From the documentation:
In node,
require.paths
is an array of strings that represent paths to be searched for modules when they are not prefixed with'/'
,'./'
, or'../'
.(emphasis mine)