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\".
\"../test1/folder1/FolderIWant/test.txt\"
I want to get
const path = require("path") path.dirname(path.basename(__dirname))
Better use @danielwolf's answer instead
Use split() and pop():
split()
pop()
path.dirname(filename).split(path.sep).pop()