fs: how do I locate a parent folder?

fancy picture fancy · Aug 16, 2011 · Viewed 182.8k times · Source

How do I write this to go back up the parent 2 levels to find a file?

fs.readFile(__dirname + 'foo.bar');

Answer

Andrew Hare picture Andrew Hare · Aug 16, 2011

Try this:

fs.readFile(__dirname + '/../../foo.bar');

Note the forward slash at the beginning of the relative path.