How to: TiddlyWiki on NodeJS + nginx proxy + LetsEncrypt

I wanted to spin up a nodejs based TiddlyWiki for myself that would allow me easy access (provided I have internet) and it took a little bit to understand how all the pieces would fit together. Now that I know and am quite happy with the result I decided to share the knowledge here for others. For this guide I’m using Ubuntu Server 21.04 minimal.

Initial Setup

  1. Get yourself a server, I’m using a Google Cloud free-tier instance but anything should work
  2. Get yourself a domain, point @ and www at the external ip address of your server (you can also use a subdomain rather than @ and www)

Install Node

  1. sudo apt update - update the list of packages available
  2. sudo apt install nodejs npm - this will install nodejs and the node package manager making it easy to install TiddlyWiki, speaking of:

Install TiddlyWiki

  1. sudo npm install -g tiddlywiki - globally installs the tiddlywiki command
  2. mkdir ~/wiki- creates a wiki folder in our home directory, this will contain the wikis content
  3. cd ~
  4. tiddlywiki wiki --init server - fills the wiki folder with the basic files necessary for an empty wiki
  5. nano ~/wiki/users.csv - start editing the list of users and credentials that can be used to log into the wiki, a sample version of this file can be found here:

Install nginx + Let’s Encrypt

  1. sudo apt install nginx
  2. cd /etc/nginx/sites-available
  3. sudo nano - create and edit the configuration for our proxy server
server {
    client_max_body_size    100M;
    location / {
    proxy_set_header        Host             $host;
    proxy_set_header        X-Real-IP        $remote_addr;
    proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;

This will forward all traffic arriving at to our wiki running on port 8080. It will also bump up the upload limit in case you wish to upload files larger than 2M.
4. sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled - this will enable the proxy
5. sudo apt install certbot python3-certbot-nginx - installs the Let’s Encrypt client and nginx plugin
6. sudo certbot --nginx - follow the instructions to create and install a certificate.

Run TiddlyWiki

  1. cd ~

You now have a couple of different ways of starting the server based on who you’d like to give access

  • tiddlywiki wiki --listen - starts the wiki but everyone has read/write access
  • tiddlywiki wiki --listen credentials=users.csv "readers=(anon)" "writers=(authenticated)" - now anyone can read but only logged in users can edit
  • tiddlywiki wiki --listen credentials=users.csv "readers=(authenticated)" "writers=(authenticated)" - completely private wiki, you need to log in to view, but you also get edit access

Once you’ve run one of the following commands you should be able to open your browser and go to your domain ( here) and find your fresh new TiddlyWiki!

Bonus: Install pm2
pm2 can be used to automatically restart the wiki should it crash and will start it up whenever the system boots/reboots

  1. sudo npm install -g pm2@latest - globally installs the pm2 command
  2. pm2 start /usr/local/bin/tiddlywiki -- /home/username/wiki --listen - this tells pm2 what command to run, we need to be a little bit more explicit and so we have to pass in the full path of the tiddlywiki command and our wiki folder. Feel free to tweak this command using one of the examples above to add authentication
  3. pm2 startup will enable pm2 and the running of any services at boot

Awesome! This was on my list to document, thank you for sharing!

That is really fantastic documentation !!!

I just recently figured out how to get a “TiddlyWiki farm” (i.e. a bunch of TiddlyWikis) working in a Google Cloud Compute vm.

My setup involves TiddlyWiki on nodejs and nginx, but I used systemd for auto-launch on reboot of the machine.

(I must now look into “Let’s Encrypt”.)

Being really new to all of this, I wonder how systemd (which was already there with Debian) does compared to pm2. Are they pretty much six-of-one, half-a-dozen of another? (I’m wondering if pm2 would make my life easier the next time around.)

systemd is for system level services. NodeJS can crash, and pm helps detect this and will reboot it, without rebooting the whole server.

That’s the rough answer, you can combine the two by using systemd to run TW using pm.

Systemd is the system level init system which can be used to keep services alive and start them at boot. I bet you had to either write the systemd unit by hand or copy it from someone else. pm2 is nice because it will generate that unit for us. During regular operation it will monitor tiddlywiki and node, should they crash pm2 will restart them for us. Then on boot the systemd unit that it generated will start the monitoring up for us.

Really well presented! Mahalo (thanks)!