Node.js path.extname() Method
The path.extname() method is used to get the extension portion of a file path. The extension string returned from the last occurrence of a period (.) in the path to the end of the path string. If there are no periods in the file path, then an empty string is returned.
path.extname( path )
Parameters: This method accepts single parameter path which holds the file path that would be used to extract the extension.
Return Value: It returns a string with the extension portion of the path. It throws a TypeError if this parameter is not a string value.
Below examples illustrate the path.extname() method in node.js:
.txt .md . .txt .js
/home/user/website/index.html /home/user/website/contact_us.html /home/user/website/services.html