Failed Experiment

I have a feeling I have to try and retrieve things from my SQL with python and not JavaScript. I’ve googled a lot, and it seems JavaScript can’t handle database retrieval client side. I put my database, my html file, and my javascript file in the same folder, double click my html file to have my default browser run it.
I can get the message retrieved from my database, but I can’t get it to assign it to anything I can use.
My database is simply has a table named test, with the values:
id = 1 and message = “Animal crackers in my soup”
alerts only work in HTML, console.log in the console
I’m going to give up on this idea, but if anyone wants to take a crack at it:

// Get fields from the mySQL database:

const sqlite3 = require('sqlite3').verbose();
const path = require('path')
const dbPath = path.resolve(__dirname, 'GameScore.db')

const db = new sqlite3.Database(dbPath, (err) => {

function getMessage() {
  //var x = "None";
  db.serialize(() => {
  db.each(`SELECT id as id, message as message FROM test;`, (err, row) => {
    if (err) {
    // No Error
    // HOW DO I GET my row.message out of these call backs?
    return row.message;
  // here my row.message is gone.

function MyFunction(){
  message = getMessage();

  //document.getElementById("MyMessage").innerHTML = message;
  console.log(message); //'None'



picture attached of result in console.

1 Like

Yes, I think you can’t retrieve a database from client side with pure javascript. You need something in the middle (a framework) that comunicates with the server. Javascript alone can only alter things inside the actual brower window. This is by design for security reasons.
With a pure Nodejs program you should be able to retrieve data from a database.
But I’m no expert in this, don’t take my word for granted.

1 Like

Uhhh I think there’s a database API for the client side, but it’s a MONSTER to understand.