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)


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


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

Related articles: