EN
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.
1. Import path module using:
const path = require('path');
2. Use path.parse() method that returns an object whose properties represent significant elements of the path.
Practical example:
const path = require('path');
// example path
const myPath = 'C:/projects/app/index.js';
const result = path.parse(myPath);
console.log(result);
Output:
{
root: 'C:/',
dir: 'C:/projects/app',
base: 'index.js',
ext: '.js',
name: 'index'
}