Languages
[Edit]
EN

Node.js - get file name with extension from path

0 points
Created by:
Mahir-Bright
261

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