0

I built a node module for others to import into their node projects. I use config.js. I'm having issues telling their scripts where to look for my config directory is.

I'm using this code to define it within my module, but its doesn't cover all possible scenarios.

var config_dir = path.dirname(process.mainModule.filename)+path.sep+'node_modules'+path.sep+'open-payments'+path.sep+'config';
process.env.NODE_CONFIG_DIR=config_dir

I need something that will tell my module where to look regardless of what or where the script is that's using my module.

1 Answers1

0

You can use __dirname to get the full path for the current executing script (i.e. not necessarily the one that was called with node, but the one where __dirname was queried).

See this question for more details: How to get path to current script with node.js?

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308