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
  • 53,718
  • 65
  • 205
  • 331

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
Kijewski
  • 25,517
  • 12
  • 101
  • 143