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.

1
  • 1
    Get the path from where? What's the relation between the gulpfile and wherever you need the path? Commented Dec 16, 2015 at 17:02

1 Answer 1

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?"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.