Getting Started with Node.js on Windows: TW5 Tribal Knowledge — TiddlyWiki Notes and Tips

TW5 Tribal Knowledge

TiddlyWiki Notes and Tips

Home

Recent
13th March 2022
9th February 2022
Tags Android BOB Books Example Community Creating a Static Site General Google App Engine Home Indieweb node.js Not Tiddlywiki PHP Platforms Plugins Syntax Tiddlywiki Development Timelines UI Changes Category Feed Font Awesome 5 Knowledge Base Listreveal Regular Solid tlwcode tlwcoreui tlwui toc Usability

Getting Started with Node.js on Windows

This how-to will describe how to download and install Node.js on your Windows machine. It isn't too difficult but you might want to consider running BOB instead.

Again, this is about running Node.js on a Windows PC that you own (in this example, Windows 10). Setting Node.js up on a hosting provider is a bit different and not part of this tutorial.

This tutorial with show you how to:

  • Run Tiddlywiki on Node.js without installing Node so I can carry it around on USB or keep it in Onedrive or Dropbox (or similar) to sync between PCs
  • Start your wiki and require a username and password
  • Start your wiki on a port other than 8080
  • Install a self-signed certificate so I can run my wiki with HTTPS to be more secure in a shared environment

Download Node.js

  • Download the windows binary ZIP file from here: https://nodejs.org/en/download/
  • Unzip your file to a directory where you will install and run your tiddlywikis from. This will all be self-contained so you can move this directory later.

For illustration, I'll unzip my Node.js files to D:\OneDrive\twnode

  • Next open a command prompt and navigate to the folder you just put the node files into (e.g., D:\OneDrive\twnode)
  • Install tiddlywiki by typing:
    npm install -g tiddlywiki
  • You can check if tiddlywiki is installed by checking the version:
    tiddlywiki --version

You'll also see the tiddlywiki files in your directory

Create a new Wiki

Next, you can create a brand new wiki to test everything out. We'll call it mynewwiki.

Execute the following commands from the folder where you installed Tiddlywiki (e.g., D:\OneDrive\twnode)

  • Initialize the server:
    tiddlywiki mynewwiki --init server
  • Next we start the server. This would be the command you use anytime you want to start this server:
    tiddlywiki mynewwiki --listen
  • You can get fancier by requiring a username and password:
    tiddlywiki mynewwiki --listen username=joe password=bloggs

Either of the above will let you access the wiki on the pc it is running on as either 127.0.0.1:8080 or localhost:8080. It won't be available to anyone else on the network.

Accessing your wiki from other computers on your LAN

Maybe you have an always-on pc that you'd like to run your wiki on and access it from a mobile device or another computer in the house. It's a nice feature but it does come with risks. If you attempt to run it on a network you don't control like a coffee shop you could be opening your wiki up to strangers.

The command to do this is simple. Start your wiki this way:

tiddlywiki mynewwiki --listen username=joe password=bloggs host=0.0.0.0

Note: You can leave off the username and password bits if you don't want them If this is the first time you are doing this on your compter you might get a prompt from the Windows Firewall asking you to allow access. Simply click the allow button.

Note that you don't access the wiki at 0.0.0.0, that is for the servers use. The details are beyond the scope of this tutorial. You still access the wiki at 127.0.0.1:8080 but you can also use the name of your computer. For example, my computer is called Kepler so I could get to my wiki at kepler:8080.

Assuming you have allowed the server through your Windows firewall as above you should be able to browse to your server from another PC on your LAN. An iOS device might not connect. What worked for me was to add .local to my url. That is, http://keplar.local:8080 in Safari or Chrome on my iPhone. Note: Safari gave me javascript errors so I recommend using Chrome.

Using a port other than 8080

If you have reason to not run your wiki on port 8080 or you want to run more than one on the same pc, you can start it on a different port. You just need to specify the port you want to run on:

tiddlywiki mynewwiki --listen username=joe password=bloggs host=0.0.0.0 port=8081

Create a batch file to star your wiki

Now lets make it really easy to start up your wiki when you want to use it. Go back to the directory where you installed tiddlywiki (e.g., D:\OneDrive\twnode). We're going to create a batch file. I like to name it the with the name of the wiki and the port it is going to run on. Create a text file called

Start_mynewwiki_8081.bat

In the text file you'll put the following:

@echo off
tiddlywiki mynewwiki --listen username=joe password=bloggs host=0.0.0.0 port=8081

Now when you want to run your wiki just double click on

Start_mynewwiki_8081.bat

HTTPS

Why go through the effort to run HTTPS? If you want to run on a public network it is worth doing to encrypt the traffic between you and your server. There is a helpful note about this on the Tiddlywiki Google Group: https://groups.google.com/d/msg/tiddlywiki/nqwfoDDIDvs/WCOSbmaSAwAJ

Get OpenSSL

Now you have to know where openssl.exe was installed. I took all the defaults and it installed it here:

C:\Program Files\Git\mingw64\bin

Next, create a folder to store your certificates. I'm using TiddlyServer so I want to store my certs inside my twserver folder. For this example we'll say my TiddlyServer folder is in c:\twserver so I want to create a certs folder in there so that path will be c:\twserver\certs.

Note: If you are following my Instructions for getting started with Node, you can just put the files below in the same folder you put Node.exe (D:\OneDrive\twnode in my examples)

Next we want to create a file called certbuilder.bat in the certs folder and put all of the following text into it:

@echo off
::https://serverfault.com/questions/845766/generating-a-self-signed-cert-with-openssl-that-works-in-chrome-58
REM IN YOUR SSL FOLDER, SAVE THIS FILE AS: certbuilder.bat
REM AT COMMAND LINE IN YOUR SSL FOLDER, RUN: certbuilder
REM IT WILL CREATE THESE FILES: key.pem, server.crt 
REM IMPORT THE .crt FILE INTO CHROME Trusted Root Certification Authorities

REM PLEASE UPDATE THE FOLLOWING VARIABLES FOR YOUR NEEDS.
SET HOSTNAME=yourwebsite
SET DOT=com
SET COUNTRY=US
SET STATE=CA
SET CITY=San Diego
SET ORGANIZATION=IT
SET ORGANIZATION_UNIT=IT Department
SET EMAIL=webmaster@%HOSTNAME%.%DOT%

(
echo [req]
echo default_bits = 2048
echo prompt = no
echo default_md = sha256
echo x509_extensions = v3_req
echo distinguished_name = dn
echo:
echo [dn]
echo C = %COUNTRY%
echo ST = %STATE%
echo L = %CITY%
echo O = %ORGANIZATION%
echo OU = %ORGANIZATION_UNIT%
echo emailAddress = %EMAIL%
echo CN = %HOSTNAME%.%DOT%
echo:
echo [v3_req]
echo subjectAltName = @alt_names
echo:
echo [alt_names]
echo DNS.1 = *.%HOSTNAME%.%DOT%
echo DNS.2 = %HOSTNAME%.%DOT%
echo DNS.3 = localhost
echo DNS.4 = 127.0.0.1
echo DNS.5 = %computername%
)>%HOSTNAME%.cnf

"C:\Program Files\Git\mingw64\bin\openssl.exe" req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout ".\key.pem" -days 3560 -out ".\server.crt" -config %HOSTNAME%.cnf

Be sure to edit everything in the section that says "Please update the following variables for your needs"!

Next you can simply double-click on the certbuilder.bat file and it will create 2 files in the certs folder that you can use in your https configuration files.

Start your wiki with HTTPS enabled

To start your wiki with https, change your start up line to:

tiddlywiki mynewwiki --listen username=joe password=bloggs tls-key=.\key.pem tls-cert=.\server.crt host=0.0.0.0 port=8081

Now you can browse to your server with https. In my example: https://kepler:8081

You will get a scary prompt from your browser because that certificate you created is one the browser is not aware of so it doesn't trust it. But you now where it is from so you can just click through. In Chrome, you click Advanced then the Proceed to... link at the bottom.

Other Node Notes

Importing from a stand alone HTML file

If you have a traditional TW5 wiki and you now want to run it on Node.js, you can import it.

  • Go to a command prompt again and get to your Install Directory
  • Assuming your wiki is in the mynewwiki folder, type:
    tiddlywiki ./mynewwiki --load path/to/my-tw5-wiki-file.html
  • If your wiki was password protected the command would be:
    tiddlywiki ./mynewwiki --password pa55w0rd --load path/to/my-tw5-wiki-file.html
  • If you want another TiddlyWiki installed you would just go back to the command line and type
    tiddlywiki myotherwiki --init server
  • Each wiki must be run on a different port

Many more details about running TW5 on Node can be found here. Including how to update your TiddlyWiki when a new version comes out.