2022-03-12
I'm doing well! My hatred for the node ecosystem has reached previously unimaginable heights. Definitely justified.
I've migrated Molly-Brown from my old server to my new one, and all was well. Until I tried to post something from my publishing portal (my web form backed by CGI scripts). Obviously I could only post to the web side of things, because the gemini server was on another machine!
Logical, but annoying. That led to some frustration, which sped up the web server migration process significantly.
Simple thing, really. I installed apache on the new server and cloned the config from the old one. Then I removed a bunch of stuff that is now redundant, pointed the web root dir to the path where I want it now, and set it to run as my user (relinquishing the need for suexec).
Boom. Worked.
I installed thelounge.chat from the .deb package provided on their homepage, and likewise copied the configuration from the old server. I also installed sqlite3, remembering that it needed that for logging history.
Then I started it. And it didn't have logging history. Apparently it couldn't load the node-sqlite3 module. I just assumed it hadn't installed it, but I didn't actually check at the time. I just ran "npm install sqlite3".
But at first I couldn't install the module sqlite3 because node-pre-gyp wasn't installed. It wasn't really listed as a requirement among the installation instructions, except casually mentioned in a paragraph. Clearly aimed at people who actually somewhat understand node. I installed that, all the time feeling that if you have to add a glue between the package manager (npm) and the build tool (node-gyp) you're probably doing something wrong.
Alright! How about now? No? Now I couldn't install node-sqlite3 because node-gyp was using python2 syntax in some file and obviously no modern system has that installed anymore. After upgrading node-gyp I could install it. Note that I installed npm this morning which pulled down node-gyp and still didn't give me the latest version. Now "npm install sqlite3" introduced vulnerabilities, which could be fixed but npm warned that "npm audit fix --force" could break things. I had enough trouble getting things working without that headache.
Even after installation thelounge couldn't find it, which made me think something might be wrong with the module. I decided to install node-sqlite3 from source (maybe they didn't have the binary for RPi or something). That caused compiler errors indicating that the dev headers for sqlite3 weren't installed on the OS, so I installed that package.
Then I got hundreds of new compile errors that were absolutely opaque. I started looking closely at the command given in the node-sqlite3 installation instructions (under the heading "On most Linuxes (including Raspberry Pi)" and all the env variables for where to find libs were wrong, plus it needed sqlciphers which I didn't have. So I installed that and then had to play detective a bit before finding the real paths to stuff. Of course none of this is explained in the instructions. The assumption is that this will just work on "most linuxes" and if it doesn't... Well, then it doesn't. At least now it compiled.
But thelounge still couldn't import it. I could from the command line, but then I discovered that it only worked when I was in /etc/node_modules and nowhere else. I thought "this smells like a JAVA_HOME thing" and searched a bit. Lo and behold: NODE_PATH is a thing. It's an environment variable you need set in order for node to understand where it has its own shit. Shouldn't the npm package for debian maybe set some sane default to point somewhere? Perhaps to where it installed its modules?
I added ' Environment="NODE_PATH=/etc/node_modules" ' to the thelounge systemd service file.
And now it works
Thinking about what I just went through I see that I leveraged my decades old knowledge of C and linux programming, my experiences with java configuration, lots and lots of general linux experience (just knowing where to look for the installed node modules feels natural to me, but isn't for everyone), python knowledge, and more. All in all I needed a wide array of skills that I've acquired hodge podge over the last 14 years.
I couldn't guide someone through this. It's something I had to be able to debug myself. For 6 hours, including a few breaks because of compile/install times.
If I didn't have all this knowledge I would have got completely stuck almost at once and never been able to progress. Imagine looking at the node-gyp stacktrace pointing out a syntax error in a generic print statement without knowing the differences between python2 and python3.
You are an expert in all these technologies, and that’s a good thing, because that expertise let you spend only six hours figuring out what went wrong, as opposed to losing your job. You now have one extra little fact to tuck away in the millions of little facts you have to memorize [...]
"Your Own Publishing Portal", the first version of my custom blog/gemlog/twtxt publishing tool.
Node-sqlite3 installation instructions.
-- CC0 Björn Wärmedal