TW5: Tiddlywiki on node.js: Show content of local text file in a tiddler

143 views
Skip to first unread message

rooster91an

unread,
May 21, 2019, 8:57:57 AM5/21/19
to TiddlyWiki
Hello everybody!

I am running a Tiddlywiki via node.js on my Raspberry Pi. This works wonderfully. Now I have some telemetry data from my network, periodically updated in a text file. It would be great, if I could show the current text content of this file in a tiddler in my wiki.

What is the best (and easiest) way to do this?

What I have tried so far:

1. I guessworked with the import and load commands of tiddlywiki on node.js. This works in principle, but to show the imported tiddlers, I had to stop and restart the tiddlywiki server after every import or load. Otherwise the new tiddlers were not shown in the refreshed browser page. Is there a way to avoid a restart of the node process?

2. I tried to use the HTML embed command in a tiddler like this:

<div style="height:60px;background-color:beige;">
<embed type="text/plain" src="data.txt">
</div>

But I did not get it working, neither with an absolute file path, nor with a relative file path. To be sure I copied the text file to the higher-level folder, to the 'mywiki' folder and to the 'tiddlers' folder. The file rights are checked and okay. No success.

Is access to local files with tiddlywiki on node.js even possible? How does it have to be formatted?

Thank you for helping me out.

Oliver

Mark S.

unread,
May 21, 2019, 9:55:04 AM5/21/19
to TiddlyWiki
To access the local file you will need, at a minimum, to activate the static file server. Not sure if it supports text documents. If you try Bob
https://github.com/OokTech/TW5-Bob it has a configuration for adding your own mime type. Possibly you could add text documents.
In either case the text would have to be in the specified static file directory.

Wait -- how is your text file being created? Could you wrap it in a process that would make it look like a tid file, and place it in the tid directory? Then with Bob (I think), it would automatically be updated in your TW.

Good luck

TonyM

unread,
May 22, 2019, 6:37:36 AM5/22/19
to TiddlyWiki


This works for me on a TiddlyWiki in TiddlyDesktop

<embed type="text/plain" src="readme.txt">

<embed type="text/plain" src="C:\Data\batches\networkcheck.txt">

<iframe src="C:\Data\batches\networkcheck.txt" width=100%/>

I can read the content

Its not working on TiddlyServer hosted wikis

However perhaps tagging with 

$:/tags/RawMarkup

will work in some cases

What is your particular setup?

Tony

rooster91an

unread,
May 22, 2019, 9:12:31 AM5/22/19
to TiddlyWiki
Hi Mark,
you wrote 'you will need, at a minimum, to activate the static file server'. I'm just running the tiddlywiki web server at node.js as described at tiddlywiki.com and I am accessing it via https. What static file server do you mean? Is it another node module?
Thank you!

Oliver

rooster91an

unread,
May 22, 2019, 9:43:27 AM5/22/19
to TiddlyWiki
Hi Tony,
thank you for your answer. I've seen that the embed command works on file based Tiddlywikis. Running Tiddlywiki at node.js as a webservice is crucial to my current project though. My setup is:

- a raspberry pi with raspbian stretch lite in version April 2019 (current release)
- installed nodejs from raspbian repository
- installed tiddlywiki as described at tiddlywiki.com (npm install -g tiddlywiki)
- running tiddlywiki with a 'tiddlywiki mywiki --listen host=x.x.x.x port=xxx username...' like command

The Tiddlywiki for itself runs perfect. The challenge is, to show content of a text file on the local raspberry pi filesystem in a tiddler.

But in this environment the HTML embed command delivers no data. It seems that the nodejs-based Tiddlywiki webserver prevents the reading of local files at all. It would be interesting, if this behaviour is mandatory or if it can be changed by nodejs configuration or so.

Oliver

Mark S.

unread,
May 22, 2019, 11:58:03 AM5/22/19
to TiddlyWiki
Web-based apps don't know anything about local files unless those local files are also being served. The node.js server didn't use to be able to serve up supplementary files, such as images.

But now now there is a static file server built in. But it's limited where it serves from and what files it serves:

https://tiddlywiki.com/#Using%20the%20integrated%20static%20file%20server

Bob is another webserver that was actually designed for (if memory serves) the needs of the Raspberry Pi. It allows you to specify the directory where your static files are kept (I think, I've only used it occasionally). It allows you to run multiple wikis without additional processes (do I have that right?). Bob has a configuration that allows you to add new mime types. So you might be able to add in the mime type for text files.

TiddlyServer is another webserver, and it allows you to serve up images. This may be unsafe in a "coffee-shop" environment, since any files on your device could be fetched.

If the text files you want to server can't be exported to a directory seen by node.js, then possibly you could put a symbolic link in the files directory leading to your text file directory.

Good luck!

rooster91an

unread,
May 23, 2019, 2:29:11 AM5/23/19
to TiddlyWiki
Hi Mark,
this is it! Showing the data by using the integrated static file server absolutely fits my demands. With a <embed src="https://myserver.xyz/files/mydata.txt"> like command in a tiddler I have everything I need.

Thanks a lot for your patient help.

Oliver

Alex

unread,
Jun 11, 2019, 5:28:41 AM6/11/19
to TiddlyWiki
Maybe a bit late for the party, but you may also want to read this:

https://tiddlywiki.com/#tiddlywiki.files%20Files

It works like this: you create a subfolder under $ROOT/tiddlers, and put a single file tiddlywiki.files there. If the file is created correctly, it will tell TW to parse files somewhere else on the file system as if they were tiddlers in this folder.

Although, IMHO, symbolic link to $ROOT/files subfolder is easier :)
Reply all
Reply to author
Forward
0 new messages