Home > Web Front-end > JS Tutorial > Instructions for using the path.basename method in node.js_node.js

Instructions for using the path.basename method in node.js_node.js

WBOY
Release: 2016-05-16 16:28:06
Original
1591 people have browsed it

Method description:

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

Grammar:

Copy code The code is as follows:

path.basename(p, [ext])

Since this method belongs to the path module, the path module needs to be introduced before use (var path= require(“path”) )

Receive parameters:

p The path to be processed
ext Characters to filter

Example:

Copy code The code is as follows:

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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template