Quick Intro to Path module - Node.js
The path module provides a way to work with files and directory path.
path.dirname()
This method allows you to get the directory name of a given path. It does not return the last part of the given path.
path.basename()
This method returns the last part of a given path.
If you only want the filename and not the extension, add the file extension as the second argument in the method.
path.extname()
This method returns the extension of the path from the last part of the path.
path.normalize()
This method normalize the given path, by resolving '..', '.' etc.
If multiple slashes are found they are replaced by a single slash.
path.join()
This method joins all the given path segments together. All the arguments must be string. It also normalizes the resulting path, means it fixes the path strings likes '..'. '\\\' etc.
Zero-length path segments are ignored.
These are some of the commonly used methods from path module.
See full documentation here.
Comments
Post a Comment