Sometimes, we want to get file name from absolute path with Node.js.
In this article, we’ll look at how to get file name from absolute path with Node.js.
How to get file name from absolute path with Node.js?
To get file name from absolute path with Node.js, we can use the path.basename
method.
For instance, we write
const path = require("path");
const fileName = "C:\Python27\ArcGIS10.2\python.exe";
const file = path.basename(fileName);
to call path.basename
with the fileName
path string.
As a result, file
is 'python.exe'
.
Conclusion
To get file name from absolute path with Node.js, we can use the path.basename
method.