T
T
Torento203452021-07-13 15:41:27
Node.js
Torento20345, 2021-07-13 15:41:27

Why doesn't the path from the file work without the path module?

There is a subfolder with a file in it.
When I try to go up to the root '../../folder/foo.js', I get an error that there is no such file.
But when path.join(__dirname, '../../folder/foo.js')- finds the file.
Why can you do without it path?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2021-07-13
@search

It is important to know how you are accessing the file. But I'm ready to assume that this is something like fs.readFile. If you pass a relative path to most fs module functions, the file will be resolved relative to the project's working directory. The project's working directory can be found by running process.cwd().
The working directory of a project usually does not change from module to module.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question