Seeking testers for a tiddlywiki node.js launcher on macOS

I asked chat gpt to create a mac os version of my .bat script, however I don’t own a mac so could anyone review the code / test it and confirm if this works ?

Here’s the script: TWNodeJSLauncher/TWNodeJSLauncher_MacOS.sh at main · Telumire/TWNodeJSLauncher (github.com)

And here’s what it (should) do:

  1. Check for Node.js Installation: The script first checks if Node.js is installed on the system. If it’s not found, it informs the user that Node.js needs to be installed, provides a link to the Node.js website, opens that link in the default web browser for convenience, and then exits to prevent the script from running further.
  2. Check for TiddlyWiki Installation: Next, it checks if TiddlyWiki is installed globally on the system. If TiddlyWiki isn’t found, it proceeds to install TiddlyWiki globally using npm (Node Package Manager).
  3. Initialize Variables: It initializes some variables, including an empty name variable for the wiki name, a startPort variable set to 80 for the starting search port for the server, and a freePort variable to store the discovered free port.
  4. Find a Free Port Function: The script defines a function, find_free_port, that iterates starting from port 80 (or whatever startPort is set to) upwards until it finds a port that is not in use. It checks port availability by attempting to connect to each port on localhost and increments the port number until a free one is found.
  5. Main Logic:
  • If the script is run with a single argument ending in .html, it assumes the user wants to convert a single-file TiddlyWiki into a wiki folder. It does so using the tiddlywiki --load command, saving the result to a new folder named after the HTML file without its extension.
  • If no argument or a different argument is provided, the script then prompts the user to enter a name for the wiki or uses the provided argument as the name.
  • It removes any quotation marks from the wiki name.
  • The script looks for a free port by calling the find_free_port function.
  • It checks if the specified wiki folder exists and is empty. If so, it initializes a new TiddlyWiki in that folder.
  • It then opens the wiki in the default web browser at localhost on the discovered free port.
  • If the wiki folder doesn’t have a start.sh script, it creates one to facilitate starting the wiki server in the future.
  • It checks for a site title file within the wiki’s tiddlers folder. If not found, it creates a JSON file with the wiki’s name as the site title and loads it into the wiki.
  • Finally, it starts the TiddlyWiki server with filesystem and tiddlyweb plugins enabled, listening on the discovered free port.

I use M1 Pro Macbook, the MacOS version shell script basically works as expected, here are my findings:

  • 80 port is not taken, but I cannot start web server using ./twlauncher.sh Launcher with normal user: :no_entry_sign:
node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied 127.0.0.1:80
    at Server.setupListenHandle [as _listen2] (node:net:1855:21)
    at listenInCluster (node:net:1920:12)
    at doListen (node:net:2075:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1899:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'EACCES',
  errno: -13,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 80
}

Node.js v20.11.1
  • If I sudo ./twlauncher.sh Launcher the same script, it could access 80 port, but to my surprise it opens Edge browser in Windows (Parallels Virtual Machine) instead of opening MacOS default browser. :thinking:

  • If I change the start port from 80 to 8000, no errors, URL opened in MacOS default Firefox browser, except that the URL opens so promptly that it doesn’t wait for node web server fully started. :sweat_smile:

  • If I change the start port from 80 to 8086, which is already taken by other server, no errors, port automatically switched into currently unused 8087, URL opened in MacOS default browser, only too promptly. :ok_hand:t2:

Thanks for sharing your script which demonstrates how to get free available port, I’m trying to do something similar with the help of Platypus App wrapper and python tools (gooey). :smiley:

1 Like

These are basically what tiddlywiki-starter-kit does, except that it does not require users to install software globally, but is a separate project. It has no platform requirements and any operating system will do. for reference only

So you can see its online presentation on stackbitz

https://stackblitz.com/~/github.com/oeyoews/tiddlywiki-starter-kit

Unix systems and also windows should not allow users to assign port numbers below 1024 in user-space.

So you should not start searching for free ports at 80. Many ports below 1024 are reserved for dedicated system applications. eg: port 443 is usually reserved for the HTTPS protocol.

There is a reason, why most http servers use 8080 as a default port value. It was reserved as “http-alt” an alternative port 80 in userspace.

The port number registry in general is very “crowded” as you can see in the http-alt link but as long as your system does not run any of the “registered” services it is save to use any of the listed ports above 1024

If you start at 8000 I think the intention should be clear, that you want to start an http-server, because 8080 is widely known, but very likely to be used by someone else already.

2 Likes

Bummer, I will try to fix these issues. Thanks for testing and taking the time to provide a detailed feedback !

That looks very nice ! Is there a way to launch a “default” tiddlywiki with tiddlywiki-starter-kit (without Tailwind for example) ?

I didnt know that, this is very interesting. I will make adjustments to the script to take this into account, thanks !

may be you like this create-tw-apps

1 Like