Home  >  Q&A  >  body text

How to activate my nodejs function from another js file?

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粉833546953P粉833546953235 days ago552

reply all(1)I'll reply

  • P粉838563523

    P粉8385635232024-02-27 19:37:08

    nodejs is used for backend.

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

    reply
    0
  • Cancelreply