Launching TiddlyWiki as a node.js app dependency

I have a node.js app that is using TiddlyWiki and tiddlers as a database. Currently clone tiddlywiki5.git into a sub-directory of the app and start it up

// Access to TiddlyWiki functions - boot, utils, Tiddler, and Wiki
const $tw = require('./tiddlywiki/boot/boot.js').TiddlyWiki();

// Pass the command line arguments to the boot kernel
$tw.boot.argv = ['--version'];

$tw.boot.boot(() => {
	console.log('TiddlyWiki loaded');

So have a ‘$’ with the core, add, delete, functions, and cool stuff!

If I were to set tiddlywiki as a dependency in my package.json would I have to go thru ‘node_modules/tiddlywiki’ to get to boot.js? … or is there a better way of loading a somewhat bare tiddlywiki that has modules loaded, Tiddler, and Wiki instances all setup?

Any pro/cons/issues on using TiddlyWiki in this way - (without a DOM) would be appreciated.

I think nowadays you can just require("tiddlywiki/boot/boot.js"), but I still have plenty of code that works along the lines you suggest.

The code you posted is the preferred way to go if you don’t need fine control over the boot process. Here’s an example of the code used to run TiddlyWiki as a Lambda function on AWS. By invoking the two parts of the boot process separately we can easily inject tiddlers into the store:

TiddlyWiki is intended to be runnable wherever JavaScript is spoken, so this looks perfectly reasonable.


Did that and works fine - then got to thinking - if “main” in TiddlyWiki’s package.json was “./boot/boot.js” then require('tiddlywiki').TiddlyWiki() would work too. And it does!

Thanks for the AWS example, never would have found that one. Does exactly what I need. I wanted to load the database on startup but unsuccessful so far as it is compressed (being JSON, is silly big). Perfect example - your the best!

Thanks @poc2go, that does read better.

Great, I hope you’ll be able to share what you’re working on.

It might be helpful to write up the AWS Lambda stuff on

30 posts were split to a new topic: Node-Red Based Low-Code Server to Dynamically Create TiddlyWiki’s

See how I use tiddlywiki as a library in TidGi’s worker_thread

Also in the test

Your usage of node-red is interesting, I was thinking about a similar idea that uses low code tool like it to create background task like “auto create Journey / daily note on 00:00”

I used TW as an app import in my system tw-bookcase.

const bootprefix = require('tiddlywiki/boot/bootprefix').bootprefix;
const TiddlyWiki = require('tiddlywiki/boot/boot').TiddlyWiki;
1 Like