Path. Basename method in node.js

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

Method description:

Extract the last part of the path separated by '/'. (see examples for details)

Grammar:


path.basename(p, [ext])

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                                      Path to process
Ext                                The character to be filtered

Example:


var path= require("path");
path.basename('/foo/bar/baz/asdf/quux.html')
// returns
'quux.html'
 
path.basename('/foo/bar/baz/asdf/quux.html', '.html')
// returns
'quux'
 
var a = path.basename('/foo/bar/baz/asdf/', '.html');
// returns
'asdf'


Related articles: