I’m trying to insert data from an Sqlite3 database into a web page hosted by a Beaglebone black.
Using a Java Script web worker form an on line example for a number count, the JS worker and HTML page work fine. If I modify the worker code to get the data from a database,and run that in a terminal on the host, that also works fine, the data base is accessed and the data printed out. However, the code will NOT operate as a worker.
HTML code (wkr_tst.html)
<html>
<body>
<p>Count numbers: <output id="result"></output></p>
<p>Count numbers: <output id="result2"></output></p>
<button onclick="startWorker()">Start Worker</button>
<button onclick="stopWorker()">Stop Worker</button>
<script>
var w;
function startWorker() {
if (typeof(Worker) !== "undefined") {
if (typeof(w) == "undefined") {
w = new Worker("dbase1.js");
}
w.onmessage = function(event) {
document.getElementById("result").innerHTML = event.data;
document.getElementById("result2").innerHTML = event.data;
};
} else {
document.getElementById("result").innerHTML = "Sorry! No Web Worker support.";
}
}
function stopWorker() {
w.terminate();
w = undefined;
}
</script>
</body>
</html>
Java script worker:(dbase1.js)
const sqlite3 = require("sqlite3")
var i = 0;
const db = new sqlite3.Database("/home/debian/examples/C_BMS/test2.db",sqlite3.OPEN_READONLY );
function timedCount() {
i=i+1;
db.all("SELECT * FROM EpiData", [], (err, rows) => {
console.log(rows);
})
postMessage(rows);
//postMessage(i);
//postMessage(i+2);
//setTimeout("timedCount()",500);
}
timedCount();
db.close();
With 2 different browsers, using the inspect function, both show that the “require(Sqlite3) function is not defined.
I’ve tried re-installing both Nodejs and the squlite3 extension, with the same result.