I was tracking down a vexing problem in my node app. I was converging on my problem being a memory leak in a 3rd party node module, and decided to do an npm update.
I typed in npm update and, without thinking, pressed [Enter]. Yeah. Smart move dumbass. Completely hosed my app. Serves me right. For those in our studio audience, what I did was blindly update every node_module–3rd party components my app depends on–to their latest version. All. At. Once. As Gimli said: “Small chance of success. Certainty of death. What are we waitin’ for?”
To recover, I had to get rid of all of the node_modules. But–yes I use Windows 8 (on a touchscreen laptop)–so, the paths to these modules exceed the maximum limits supported by the relevant commands and so I couldn’t delete all of the node_modules!
I luckily found a great tip on the web.
1) Create a new directory. Put nothing in it.
2) Open cmd prompt, and: Robocopy [new_directory] [node_modules directory to delete] /RIM
3) Be amazed. The /RIM is the key because it removes any files in the target directory that are not found in the source directory.
The result was that the target directory was gone.
I reinstalled nodejs (which also installs npm).
Then, in my project directory, I ran: npm install, and npm install -dev. This used the project’s package.json file, and restored the versions listed there.
What a stunningly dumb move on my part. Fortunately, the above worked and my app is running again, but not without a tremendous amount of pain and suffering…a true self-inflicted head wound. I need to figure out some safeguards to not do this again–especially difficult since I don’t get to write code that often and have to come back to this after weeks away. But such is life.
Now. What the hell was I trying to fix?