我正在使用 oracledb 作为节点从数据库中获取数据。获取数据后,我尝试使用express JS 中的render()将数据发送到客户端。代码是这样的 -
配置.js
module.exports = {
user : "user",
password : "password",
connectString : "*connstring*" ,
deliveredQuery: " SELECT COUNT (DISTINCT order_num) AS Cnt from orders where department = 'HR'
};
查询2.js
module.exports = function(callback) {//pass callback function and return with this
var oracledb = require('oracledb');
var dbConfig = require('./config.js');
this.queryDB = function(query,callback) {
oracledb.getConnection({
user: dbConfig.user,
password: dbConfig.password,
connectString: dbConfig.connectString,
deliveredQuery: dbConfig.deliveredQuery
}, function(err, connection) {
if (err) {
console.error(err.message);
return callback(err);
}
connection.execute(query, function(err, result) {
if (err) {
console.error(err.message);
doRelease(connection);
return;
}
//console.log(result.metaData);
//console.log(JSON.parse(result.rows[0][0]));
doRelease(connection);
return callback(null, JSON.parse(result.rows[0][0]))
});
});
function doRelease(connection) {
connection.release(function(err) {
if (err) {
console.error(err.message);
return callback(err);
}
});
}
};
};
serv_ontime.js
var dbConfig = require('./config.js');
var res = require('./query2.js')();
var onTime_query = dbConfig.onTime_query;
module.exports = function (callback) {
queryDB(onTime_query, callback)
};
应用程序.js
var express = require('express');
var path = require('path');
var app = express();
var port = process.env.PORT || 5000;
var serv_ontime = require('./serv_ontime.js');
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/src/views');
var bookRouter= express.Router();
app.set('view engine','ejs');
bookRouter.route('/')
.get(function(req,res){
serv_ontime(function(error, result){
res.render('index',
{title: 'Hello',
rec: result
});
});
});
现在,当我在 cmd 中执行node app.js时,它显示以下错误 -
谁能帮我理解我在这里做错了什么?