0

If you have a module that's being imported in some code, let's say...

var my_cool_module = require('my_directory/my_cool_module');

my_cool_module.print_directory_name();

And I'm in that module's context, say this is the file my_cool_module.js...

function get_dir_name() {
  // get the directory name...
  return directory_name;
}

exports.module.print_directory_name = function() {
  console.log("This module is in directory " + get_dir_name());
};

How can I get the directory that the module is in (i.e. "my_directory")

1 Answers1

0

I found out from the node.js documentation here that you can use __dirname

function get_directory_name() {
  return __dirname;
}