EN
TypeScript / Node.js - parse path to parts: directory, filename, extension, etc.
0 points
In this article, we would like to show you how to parse path to parts in Node.js.
In this example, we use path.parse()
method that returns an object whose properties represent significant elements of the path.
xxxxxxxxxx
1
import * as path from 'path';
2
3
// example path
4
const myPath: string = 'C:/projects/app/index.js';
5
const result: path.ParsedPath = path.parse(myPath);
6
7
console.log(result);
Output:
xxxxxxxxxx
1
{
2
root: 'C:/',
3
dir: 'C:/projects/app',
4
base: 'index.js',
5
ext: '.js',
6
name: 'index'
7
}
Note:
Go to this article to see how to install Node types.