'any way to connect javascript to sqlite3 that is on my raspberryPi?

Im trying to do a small login website(nginx) with a sqlite database on my raspberry but im finding it hard to connect to the database through the javascript to allow login or not.

my login page is a simple html form with a button that should have my function as a onClick.

I hope to be able to connect to database on the onClick script and send the info to the database or retrieve.

(i did something similar with php and mysql a few years back but i cant seem to find a way to do this with javascript and sqlite)

example of my login.js:

function test(){
 const sqlite3 = require('sqlite3').verbose();

 let db = new sqlite3.Database(':memory:', (err) => {
     if (err) {
         return console.error(err.message);
     }
     console.log('Connected to the in-memory SQlite database.');
 });                                                                                           
}

this breaks at the require() i dont quite understand node.js yet but i think it is something related to that.

update 1:

this is the error message -
error message when testing with intelij

after searching a bit more for solutions i think it is something to do with client side javascript or node.js? im a beginner in JS so i dont really understand it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source