How to get __dirname to point to the preserved path of the folder rather than the real path of the symlinked file when using npm link.
Scenario
Folder Setup
project
|
---- moduleA
| |
| ---- moduleA.js
|
---- app
|
--- node_modules
cd project/moduleA
npm link
cd project/app
npm link moduleA
Inside moduleA.js
__dirname -> /project/moduleA
However, the expected behavior is
__dirname -> /project/app/node_modules/moduleA
since npm link creates a sym-link that inserts the linked module in the node_modules folder hence simulating the experience of installing the module directly.
How can I get __dirname to point to the preserved path rather than the real path where the module is located?
NOTE: --preserve-symlinks command line option does not affect the value of __dirname