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
- Get yourself a server, I’m using a Google Cloud free-tier instance but anything should work
- Get yourself a domain, point
@
andwww
at the external ip address of your server (you can also use a subdomain rather than@
andwww
)
Install Node
-
sudo apt update
- update the list of packages available -
sudo apt install nodejs npm
- this will install nodejs and the node package manager making it easy to install TiddlyWiki, speaking of:
Install TiddlyWiki
-
sudo npm install -g tiddlywiki
- globally installs thetiddlywiki
command -
mkdir ~/wiki
- creates a wiki folder in our home directory, this will contain the wikis content cd ~
-
tiddlywiki wiki --init server
- fills the wiki folder with the basic files necessary for an empty wiki -
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: https://tiddlywiki.com/#WebServer%20Parameter%3A%20credentials
Install nginx + Let’s Encrypt
sudo apt install nginx
cd /etc/nginx/sites-available
-
sudo nano example.com
- create and edit the configuration for our proxy server
server {
server_name example.com
client_max_body_size 100M;
location / {
proxy_pass http://127.0.0.1:8080;
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 example.com
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/example.com /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
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 (example.com
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
-
sudo npm install -g pm2@latest
- globally installs the pm2 command -
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 -
pm2 startup
will enable pm2 and the running of any services at boot