How to activate my nodejs function from another js file?
P粉833546953
P粉833546953 2024-02-26 22:35:53
0
1
613

I have a database that stores all the users who have logged into my website and want them to be able to delete their account. So I made a function that works and removes the user's accs, but the only problem I'm having is that I can't seem to connect the js file that has the button event listener to my nodejs file with the function.

// node.js file
let id = 1;
/* delete user from mysql db */
async function delUsers() {
    /* actually hardcoded id, need to implement users id when a user can login into the site */
    await pool.query('DELETE FROM user WHERE id = ?', [id]);
    console.log("Deleting..");

};
// js file
'use strict';
console.log('linked');
let del = document.getElementById('delbutton').addEventListener('click', Del);
let a = require('./delete.js');
function Del() {
let b = a.DelUser();
}

I tried using module.exports with module.import, require, sessionstorage, localstorage. I want my button to work and delete my 1 user

P粉833546953
P粉833546953

reply all(1)
P粉838563523

nodejs is used for backend.

Global objects "window, document..." are only included in the browser.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template