I have written a CLI in Node.js, that you can globally install using npm. Now I want to run a specific piece of code the first time a user runs my CLI. But it should only run once.
My question is: How could I detect that the CLI is run for the very first time?
Of course, I could write a file into the user's home directory, and if it exists, skip code execution. This would be pretty simple.
But now things get slightly more complicated: I want this check to be re-run when the user updates the CLI to a new version. So, again, I could write a file into the user's home directory, and store the versions in it, for which I have run the "once"-code block.
But this again means that every time the user runs the CLI it has to open the file, parse it, look for the version, and so on. I fear that this could negatively impact startup performance.
Is there a better way to solve this?