While passing address in nodejs, when to place '/' between directories and when to place '\' . And why do we place dot(.) before writing addresses
Asked
Active
Viewed 35 times
2 Answers
0
path package provides functionality so that you don't need to worry about what directory separator you need to use.
const path = require('path');
path.join(parentDir, childDir);
And dot represents current directory i.e.
project index file path: /home/user/projects/project-name/index.js
you are in <project-name> folder
so index file path will be ./index.js

Harsh Kanjariya
- 503
- 5
- 11
0
In a Unix/Linux environments you place a forward slash as a folder seperator.
e.g. /home/user/image.jpg
In a Windows system you use backslashes as folder seperators, since a backslash is also an escape character in a string you should escape the backslash.
e.g. C:\users\user\image.jpg
You use a . for relative paths. e.g. if your script runs in /home/user/ and you want to access image.jpg you can do so by ./image.jpg
for more info: https://nodejs.org/api/path.html

Erwin van Hoof
- 957
- 5
- 17