3

How can I get the absolute path to the gulpfile (from the gulpfile itself)?

I wish to use the location as a reference for other relative paths.

Ben Aston
  • 49,455
  • 61
  • 188
  • 322

1 Answers1

9

gulpfile.js is just a normal script file executed in node. From inside the file __filename will point to its path:

__filename (String)

The filename of the code being executed. This is the resolved absolute path of this code file. For a main program this is not necessarily the same filename used in the command line. The value inside a module is the path to that module file.

But probably you want the directory, not the script file:

__dirname (String)

The name of the directory that the currently executing script resides in.

C.f. "How do I get the path to the current script with Node.js?"

Community
  • 1
  • 1
kay
  • 24,516
  • 10
  • 94
  • 138