Rather than reduce Raspbian by uninstalling packages and hacking down services run at boot-up to give a minimal system that runs NodeJS, I thought I’d try starting with a minimal system using RaspberryPi-UA-NetInst and just adding what’s needed.
That link gives an excellent tutorial on getting started. But before you install it, there are tweaks to be made before installing it that will get a lot of stuff set up on installing, rather than afterwards. This is a great bonus because if you ever have to reinstall, you don’t have to reconfigure the system each time. Simply format the SD card, place your modified installer files on the card, put it in the RPi and boot up, cross fingers and it’ll all be installed in under 30 minutes. And it can all be done over WiFi without touching a network cable!
So simple! Just follow Method#1 in this previous tutorial of mine, but replace the contents of on-first-login.sh with the following:
echo ------ Running /boot/CUSTOM/on-first-login.sh ---------
# output all contents of STDOUT and STDERR from this script into STDOUT *and* log file
exec &> >(tee -a ~/.on-first-login.log)
# install git
apt-get install git -y
# get the node version manager and check it out into /root/.nvm
git clone https://github.com/creationix/nvm.git ~/.nvm
git checkout v0.32.0
chmod 0755 nvm.sh
# let nvm do its stuff now
# make nvm do its stuff in future
echo "source ~/.nvm/nvm.sh" >> ~/.bashrc
# install node 6.6.0
nvm install 6.6.0
# this is a good place to put more stuff...
# eg install your server code, have the server
# start on boot-up, etc etc
echo ------ INSTALLATION COMPLETE! ---------
You might want to tweak the installer to create a user besides root, it seems to be a preferred way of doing things! But I’ll leave that to you. From here you can test out your new NodeJS server, check out this NodeJS tutorial.
This can be taken a few steps further still though! What if you want your entire NodeJS Pi server set up un an unattended fashion, right up to downloading your NodeJS source code from GitHub and running the server? And configuring systemd so it starts up automatically every time? No problem! Tutorial coming soon! 😉