Path. Extname method in node.js

  • 2020-03-30 04:33:50
  • OfStack

Method description:

Returns the path file extension, '.' if the path ends in '.', and '.' if no extension ends in '.', a null value is returned.

Grammar:


path.extname(p)

Since this method belongs to the path module, you need to introduce the path module (var path= require(" path ")) before using it.

Receiving parameters:

P            The path path

Example:


path.extname('index.html')
// returns
'.html'
path.extname('index.')
// returns
'.'
path.extname('index')
// returns
''

Source:


exports.extname = function(path) {
  return splitPath(path)[3];
};


Related articles: