R
R
Roman Basharin2016-12-29 23:55:24
Node.js
Roman Basharin, 2016-12-29 23:55:24

How to get parent directory from parent directory?

PHP has a magic pseudo-constant __DIR__, analogous to __dirname in node. But there you can just as easily request the parent of the executable file, __DIR__(__DIR__) and so on as many times as you like up to the root. And in the node I can’t google how to implement this without kilometers of code, breaking a line with forward and back slashes.
UPD
Thanks for the help gentlemen, in my case the following option came up

var path = require("path");
path.resolve(__dirname, '..', '..');

The path module should be the default, but it may need to be installed "npm install --save path"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2016-12-30
@Hellek

path.resolve(__dirname, '../..');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question