我正在尝试运行该节点。但是当我运行节点server.js时,出现错误消息“无法读取属性'recordset'。
这是文件server.js中的代码
const pool = require('./dbcon.js');
exports.loginUser = (req, res, next) => {
// const sql = require('mssql/msnodesqlv8')
// const pool = new sql.ConnectionPool({
// database: 'WebAPIDB',
// server: 'IN2408811W1\\SQLEXPRESS',
// driver: 'msnodesqlv8',
// options: {
// trustedConnection: true
// }
// })
var username = req.body.username;
console.log("USERNAME FOR MPOSTMAN")
console.log(req.body.username)
var query = "select * from emp where username like '"+username+"'";
pool.connect().then(() => {
pool.request().query(query, (err, result) => {
console.log("*** RESULT FORM DB****")
console.log(result)
if (result.recordset.length == 0)
{
return res.status(200).json({
message: "Auth Failed"
});
}
else{
console.log("in else")
console.log(result.recordset[0].password)
console.log(req.body.password)
if (result.recordset[0].password == req.body.password) {
return res.status(200).json({
message: "true"
});
}
else {
return res.status(200).json({
message: "Auth Failed password"
});
}
}
})
})
}
exports.getAllData = (req,res,next)=>{
var query = "select * from projects";
pool.connect().then(() => {
pool.request().query(query, (err, result) => {
console.log(result.recordset)
pool.close()
return res.status(200).json({
Data:result.recordset
});
})
})
}
这是我收到的错误
PS C:\Users\Karthik.BV\backend> node server.js
C:\Users\Karthik.BV\backend\controllers\user.js:98
console.log(result.recordset)
^
TypeError: Cannot read property 'recordset' of undefined
at pool.request.query (C:\Users\Karthik.BV\backend\controllers\user.js:98:32)
at _query (C:\Users\Karthik.BV\node_modules\mssql\lib\base.js:1456:25)
at StreamEvents.req.once.err (C:\Users\Karthik.BV\node_modules\mssql\lib\msnodesqlv8.js:634:11)
at Object.onceWrapper (events.js:286:20)
at StreamEvents.emit (events.js:198:13)
at errors.forEach.err (C:\Users\Karthik.BV\node_modules\msnodesqlv8\lib\reader.js:33:20)
at Array.forEach (<anonymous>)
at routeStatementError (C:\Users\Karthik.BV\node_modules\msnodesqlv8\lib\reader.js:26:14)
at invokeObject.end (C:\Users\Karthik.BV\node_modules\msnodesqlv8\lib\reader.js:258:13)
at freeStatement (C:\Users\Karthik.BV\node_modules\msnodesqlv8\lib\driver.js:160:13)
该节点未启动并且正在运行,并且我已经安装了所有必需的软件包。 我尝试调试,但似乎都没有用。 如何解决这个问题? 我无法获得任何结果。