首頁  >  問答  >  主體

如何從另一個js檔案啟動我的nodejs功能?

我有一個資料庫,其中儲存了登入我網站的所有用戶,並希望他們能夠刪除他們的帳戶。所以我做了一個可以工作的函數,可以刪除用戶的 accs,但我遇到的唯一問題是我似乎無法將具有按鈕事件偵聽器的 js 檔案與我的 nodejs 檔案與該函數連接.

// 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();
}

我嘗試將 module.exports 與 module.import、require、sessionstorage、localstorage 一起使用。我希望我的按鈕能夠正常運作並刪除我的 1 位用戶

P粉833546953P粉833546953235 天前551

全部回覆(1)我來回復

  • P粉838563523

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

    nodejs 用於後端。

    全域物件「window, document...」僅包含在瀏覽器中。

    回覆
    0
  • 取消回覆