now the top result seems to be my question
What search terms did you use?
The question is about converting relative paths to absolute in Node. If I put node.js convert relative path to absolute into a search engine (not even Google), the first result I get is the duplicate your question was linked to - it happens to be an exact title match, because someone had the foresight to title the question exactly the way that a shrewd web searcher would phrase the query. It was asked many years before your Q&A, so it should have been findable for you at the time. Similarly, I also get results like Nodejs get absolute path relative to process.cwd() and Converting an absolute path to a relative path (the other way around). If I scroll through for things off-site that are explicitly marked as published before your Q&A, I find e.g. https://medium.com/beqode/absolute-vs-relative-import-paths-nodejs-1e4efa65a7bb.
It seems like you imagined, at the time, that "even if the Node script is being run from a different directory than it is in?" represents an additional complication - but it really does not. It does, however, introduce an ambiguity: any relative path needs to be relative to something. "How do I convert a path that's relative to the CWD to an absolute path?" is different from "how do I convert a path that's relative to the script's directory, to an absolute path?".
But either of those in turn is trivial - what you're really asking is how to determine the path to which you will make the relative path, relative. Those are separate, straightforward questions which presumably have their own duplicates:
along with a lot of ancillary info or repackagings of the essential question, such as
The question received an upvote. The answer, which as far as I can tell is clear and effective, received 2 downvotes. It later received an upvote, I think it was a few months later.
Obviously, I can't go back in time (it's only been a year and 4 months, btw) and read the mind of people whose identity I didn't know. But I agree with these actions.
Your question is a fine signpost (although based on how you answered it, it seems like you considered that the main difficulty was better addressed by a different duplicate target; but people who find this question with a search engine IMO won't see it that way).
The answer is redundant, and its existence prevents signed-out users from being automatically redirected to the canonical.
Ideally, IMHO, there would be a single "managing relative and absolute paths in Node" canonical that covered these topics, like "how can I convert between absolute and relative paths?" with a single that explains that relative paths need a reference point, and then shows the few most common reference points. While we're currently trying to outlaw dupe closures to "roll-up" questions, I think these issues are closely enough related that explaining them in one place makes far more sense, and does not represent a lack of focus. For what it's worth, I have had similar frustrations with closing duplicates of the analogous questions in the Python tag.
If you told us that your question had been intended as an attempt at such - I think it missed the mark.
(In the comments, Abdul Aziz Barkat pointed out that your version of the question also talks about taking in command-line input. This aspect is clearly unrelated, and would be out of scope for any canonical - but I assume that you didn't really see it as an essential aspect of your question, since you didn't actually explain the use of argv[2] in your answer.)
__dirnamefeel like tangential rambling but make up a huge part of the answer. Consider just the trailing comment in the code block (why isn’t that regular text?!?) which takes up three times more volume for the__dirnamepart than the proper way of doing things.