ivonzhang / koa2-mongodb-server Goto Github PK
View Code? Open in Web Editor NEW利用koa2+mongodb搭建一套简易的nodejs后台服务,用于为客户端提供数据请求的数据api接口
利用koa2+mongodb搭建一套简易的nodejs后台服务,用于为客户端提供数据请求的数据api接口
看了你们的代码如
exports.findAllUsers = async () => {
var query = User.find({});
var res = []
await query.exec(function(err, users) {
if(err) {
res = []
}else {
res = users;
}
})
return res
}
controller层调 dbhelper 中的代码 , 在dbhelper 中 无论查询结果状态 controller层无法获取 ,是否可以把数据库查询的状态连同结果一起返回到 controller中 这样controller可以根据结果向客户端返回异常状态。目的则是 在复杂查询条件下 便于定位问题。
var walk = function(modelPath) {
fs
.readdirSync(modelPath)
.forEach(function(file) {
var filePath = path.join(modelPath, '/' + file)
var stat = fs.statSync(filePath)
if (stat.isFile()) {
if (/(.*)\.(js|coffee)/.test(file)) {
require(filePath) //这里的 导入不用变量接受如何使用导入的内容,导入的是 users Entity 的构造函数吧
}
}
else if (stat.isDirectory()) {
walk(filePath)
}
})
}
walk(models_path)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.