zhiqingstudy

Be a young person with knowledge and content

The path module is an official module provided by Node.js to process paths. It provides a series of methods and attributes to meet the user's processing requirements for paths

For example:

The path. join() method is used to splice multiple path fragments into a complete path string

The path. basename() method is used to parse the file name from the path string

If you want to use the path module to process the path in JavaScript, you need to import it first using the following method

const path=require('path')

1. Path. join() syntax format

Using the path. join() method, multiple paths can be spliced into a complete path string. The syntax format is as follows:

path.join([...paths])

Parameter interpretation:

... paths path fragment sequence

Return value: concatenated string

const pathStr=path.join('/a','/b/c','../','./d','e')
console.log(pathStr)  // \a\b\d\e

2. Syntax format of path. basename()

The path. basename() method can be used to obtain the last part of the path. This method is often used to obtain the file name in the path. The syntax format is as follows:

const fpath='a/b/c/index.html'
const fullName=path.basename(fpath)
console.log(fullName)  // index.html

3. Syntax format of path. extname()

Use the path. extname() method to obtain the extension part of the path. The syntax format is as follows:

path.extname(path)

Parameter interpretation:

Path: path string, required parameter

Return: get the extension string of the file

const fext=path.extname(fpath)
console.log(fext) // .html
comment
head sculpture
Code:
Related

The art of interpersonal communication and communication

A code of conduct that regulates and regulates interpersonal relationships

The importance of interpersonal relationships




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号