Does anyone have Node-swipl reference implentation

Does anyone have a working node-swipl implementation I can look at?

I want to see how it handles multiple user sessions. Our first version seems to have problems with session isolations and concurrency.

Hello! It does not handle concurrency at all. Node.js is single-threaded itself and the extension does not spawn threads for different queries. You could write a wrapper on Prolog side to spawn threads yourself and then use some query identification system to identify concurrent queries and use queues to communicate responses to them. You get a single SWI instance per Node.js process.

The alternative implementation spawns a separate SWI process per engine and supports multiple isolated engines (SWI processes) so it can process queries in parallel but without having them share the Prolog DB memory or share it with Node.js process. Queries against the same engine (instance) are still non-concurrent but the interface has built-in queue for them. It comes with JSON serialization overhead over stdio but otherwise is the simplest solution.

You could also use the Pengines library Pengines has built-in sandbox and concurrency/parallelism support for shared databases. It was originally meant for usage from browsers but the same codebase with same API also runs on Node.js. It comes with HTTP and JSON overhead.