我正在处理节点并尝试使用module.exports。
console.log(aolCount);
输出正确的值,但不会从命令return aolCount;
这是我的代码。
app.js
const express = require('express');
const aol = require('./queries/aol');
const app = express();
const port = process.env.PORT || 3000
app.get('/sample', function (req, res, next) {
res.send(aol.getAOLDataCount());
});
app.listen(port);
console.log(`Server listening on port ${port}`);
aol.js
const Sequelize = require('sequelize');
const sequelize = new Sequelize('testdb', 'root', null, {
host: 'localhost',
dialect: 'mysql',
pool:{
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
define: {
timestamps: false
}
});
let WeeklyData = require('../../models/weekly_data');
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established to the Database');
})
.catch(err => {
console.error('Unable to connect to the Database', err);
});
module.exports = {
getAOLDataCount: function () {
wd = new WeeklyData(sequelize, Sequelize.DataTypes);
wd.count({where: {week:201740, project: 8}}).then(function (aolCount) {
console.log(aolCount);
return aolCount;
});
}
};