亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

nodeJS中查詢和表達的問題

nodeJS中查詢和表達的問題

青春有我 2022-07-15 10:13:22
我正在為帶有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!';    }有誰知道發生了什么??謝謝閱讀!
查看完整描述

2 回答

?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

您將數據庫公開為默認導出database.js

module.exports = bd;

但是您正在導入它,就好像它是用名稱導出的一樣db

const { bd } = require('../database');

將導出更改database.js為:

module.exports = {
    bd: bd};

或將其導入common.js文件中:

const bd = require('../database');


查看完整回答
反對 回復 2022-07-15
?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

錯誤說 db 沒有在 common.js 文件中定義,可能是你做錯了 require('../database'); 該 require 語句中有錯誤。使用調試器在該點停止,看看你是否在那里得到 db。



查看完整回答
反對 回復 2022-07-15
  • 2 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號