What are the Path methods in Node.js
This article introduces the relevant knowledge of "what are the Path methods in Node.js". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Path.extname () returns the file extension as a string.
Path.extname ('/ path/to/test.txt') / / '.test'
Just like connecting two paths, getting a file extension is more complex than it looks at first.
If path uses. For the end, will return.. If the file does not have an extension, it does not. At the end, or the file does not have an extension, a null value is returned.
Path.extname ('/ path/to/index.') / /'. Path.extname ('/ path/to/README') / / 'path.extname (' / path/to/.gitignore') / /''
2. Path.basename () and path.dirname (), get the file name (including extension) and directory, respectively.
Path.basename ('/ path/to/test.txt') / / 'test.txt'path.dirname (' / path/to/test.txt') / /'/ path/to'
3. Path.parse () returns the object.
The object contains paths divided into five different components.
Includes extensions and directories. The path.parse () method is also a way to get the file name without any extension.
Path.parse ('/ path/to/test.txt') / * {root:'/', dir:'/ path/to', base: 'test.txt', ext:' .txt', name: 'test'} * / "what are the Path methods in Node.js?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!