Languages
[Edit]
EN

Node.js - parse path to parts: directory, filename, extension, etc.

0 points
Created by:
Lani-Skinner
408

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'
}

References

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join