EN
Node.js - get file name with extension from path
0
points
In this article, we would like to show you how to get file name with extension from path in Node.js.
1. Import path module using:
const path = require('path');
2. Use path.basename() method with the path you want to get the filename from as an argument.
Practical example:
const path = require('path');
// example path
const myPath = 'C:/projects/app/index.js';
// get file name with extension
const result = path.basename(myPath);
console.log(result); // index.js
Output:
index.js