我正在為帶有nodeJS的服務器使用express開發一個網頁。我在注冊頁面上,并且正在嘗試驗證用戶插入的數據,但是當我進行查詢時出現錯誤。auth.jsconst express = require('express');const router = express.Router();const { bd } = require('../database');const help_functions = require('../lib/common');router.post('/signup', async (req,res) => { const fullname = req.body['fullname']; const email = req.body['email']; const username = req.body['username']; const password = req.body['password']; const password_repeat = req.body['password_repeat']; var validation_msg = help_functions.validateSignUp(fullname, email, username, password, password_repeat); validation_msg = await help_functions.checkRepeatedUserEmail(email);});數據庫.jsconst mysql = require('mysql');const { promisify } = require('util');const database = { // Database credentials }const bd = mysql.createPool(database);bd.getConnection((err,connection) => { if (err) { if (err.code === 'PROTOCOL_CONNECTION_LOST') { console.error('Database connection failed !'); } if (err.code === 'ER_CON_COUNT_ERROR') { console.error('Database has too many connections !'); } if (err.code === 'ECONNREFUSED') { console.error('Database connection was refused !'); } } if (connection) { connection.release(); console.log('Database is connected !'); return; }});bd.query = promisify(bd.query);module.exports = bd;common.jsconst { bd } = require('../database');const helper_functions = {}helper_functions.validateSignUp = (fullname, email, username, password, password_repeat) => { if (fullname === '' || email === '' || username === '' || password === '' || password_repeat === '') { return 'All the fields had to be completed!'; } if (!(password.length >= 8 && (/\d/g.test(password) && (/[A-Z]/.test(password)))) ) { return 'The password needs to contain at least one capital letter, a number and 8 digits!'; }有誰知道發生了什么??謝謝閱讀!
nodeJS中查詢和表達的問題
青春有我
2022-07-15 10:13:22