I am using Node.js, and I want to obtain the parent directory name for a
file. I have the file \"../test1/folder1/FolderIWant/test.txt\"
.
I want to get
Using node as of 06-2019, I ran into an issue for accessing just filename
.
So instead, I just modified it a tiny bit and used:
path.dirname(__filename).split(path.sep).pop()
so now you get the directory name of the current directory you are in and not the full path. Although the previous answers seem to possibly work for others, for me it caused issues as node was looking for a const or a variable but couldn't find one.