0

I have a linked local custom node_module that needs to use the projects file directory: /tmp in order to dump a file there during run time. How can I direct my custom node_module to this directory?

I have tried accessing root using nodes internal path utility but this just stays within the node_modules folder.

Trying to access tmp folder by using:

var root = require('find-root')(path.resolve(__dirname));
this.tmpDir = path.resolve(root, 'tmp');

Outputs:

"/Users/me/Documents/Project/Billing/server/node_modules/processremote/tmp"

But I need it to navigate (back out of) to:

"/Users/me/Documents/Project/Billing/server/tmp"
user11317802
  • 79
  • 11

1 Answers1

0

find-root returns the directory of the closest package.json, which in your case is the directory of the child module itself (since it has a package.json file and is closest to the script).

You can fix this by using path.join(root, '../..', 'tmp') (instead of the current path.resolve(root, 'tmp')):

var root = require('find-root')(path.resolve(__dirname));
this.tmpDir = path.join(root, '../..', 'tmp');

// `tmpDir` will now be "/Users/me/Documents/Project/Billing/server/tmp"
Itai Steinherz
  • 777
  • 1
  • 9
  • 19