Simply say the meaning of these few paths:
__dirname: Gets the full directory name of the directory where the current execution file is located __filename: Gets the file name with the full absolute path to the current executable PROCESS.CWD (): Gets the folder directory name when the node command is currently executing./: directory where the files are located
Let's take a look at the current directory structure of my Computer:
syntax/ -nodejs/ -1. Findlargest.js -2. Path.js -3. Fs.js - Regs -regx.js -test.txt
In Path.js we write this code to see what the output is:
Const PATH = require (' path ') console.log (' __dirname: ', __dirname) console.log (' __filename: ', __ FileName) console.log (' process.cwd (): ', PROCESS.CWD ()) Console.log ('./: ', Path.resolve ('./'))
In the current directory nodejs
, which is the directory run node path.js
, let's look at the output:
__dirname: /users/jawil/desktop/nodejs/demo/es6-lottery/syntax/nodejs__filename: /Users/jawil /DESKTOP/NODEJS/DEMO/ES6-LOTTERY/SYNTAX/NODEJS/2.PATH.JSPROCESS.CWD ():/users/jawil/desktop/nodejs/demo/ es6-lottery/syntax/Nodejs. /: /users/jawil/desktop/nodejs/demo/es6-lottery/syntax/nodejs
Reference Link: HTTPS://GITHUB.COM/JAWIL/BLOG/ISSUES/18
The meaning of node. js __DIRNAME,__FILENAME,PROCESS.CWD (),./