process.cwd()returns directory where command has been executed (not directory of the node package) if it’s has not been changed by ‘process.chdir’ inside of application.__filenamereturns absolute path to file where it is placed.__dirnamereturns absolute path to directory of__filename.
If you need to load files from your module directory you need to use relative paths.
require('../lib/test');
instead of
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
require(lib + '/test');
It’s always relative to file where it called from and don’t depend on current work dir.