In the previous segment, you looked at some examples and understood that you should carefully use the shortcut exports as an alternative to module.exports. In case of any confusion, it is suggested to use module.exports.
In this segment, you will look at the rest of the parameters: __filename and __dirname inside the function wrapper you looked at earlier.
In the video above, you learnt about the parameter __filename.
The code which you looked at in the previous video is given below:
console.log(__filename);
This will print the absolute path of the file along with the file name.
Now, let's look at the last parameter, that is __dirname.
The code which you looked at in the previous video is given below:
console.log('File Name: ' + __filename); console.log('Directory Name: ' + __dirname);
In this segment, you looked at the parameters: __filename and __dirname.
__filename returns the file name of the current module, including the absolute path of the module file.
Example:
/Users/srishtigupta/Desktop/learn-node/app.js
__dirname returns all the directories in the hierarchical order in which the current module file resides.
Example:
/Users/srishtigupta/Desktop/learn-node