In this article, we would like to show you how to get file name with extension from path in Node.js.
path module using:
const path = require('path');
path.basename() method with the path you want to get the filename from as an argument.
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