node简易服务器完成

This commit is contained in:
aixianling
2022-03-29 15:04:07 +08:00
parent 0905e9263c
commit d48be5b91f
8 changed files with 120 additions and 13 deletions

24
utils/dbUitls.js Normal file
View File

@@ -0,0 +1,24 @@
const mysql = require("mysql");
const dbConfig = require("../config/db");
module.exports = {
pool: null,
init: () => {
this.pool = mysql.createPool(dbConfig)
},
query: sql => new Promise(resolve => {
this.pool?.getConnection((err, conn) => {
if (err) {
console.log(err)
} else {
conn.query(sql, (err, result) => {
if (err) {
console.log(err)
} else {
conn.release()
resolve(result)
}
})
}
})
}),
}