摘要:
阅读全文
摘要:返回Promise,成功则返回用户信息 const login = function (userModel,condition) { const rtn = new Promise((reslove, reject) => { userModel.find(condition, (err, docs
阅读全文
摘要:目录结构 module db.js user.ja app.js db.js const mongoose = require('mongoose') mongoose.connect('mongodb://localhost/eg', { useNewUrlParser: true, useUni
阅读全文
摘要:根据纲要(Schema)和dataBase中的集合(Collection)创建模型(Model) Schema(纲要):并没有实质性的操作集合,只是在程序中设定了一些规则,然后应用规则到数据库集合中来创建model. const userSchema= new mongoose.Schema({ /
阅读全文
摘要:数据库的连接 const mongoose = require('mongoose') // 如果数据库(database)不存在就会创建 mongoose.connect('mongodb://localhost/eg', { useNewUrlParser: true, useUnifiedTo
阅读全文
摘要:async和await是解决异步编程问题的。 promise的then方法链式调用不够优雅 async 修饰的函数同步返回一个promise 使用await必须包裹一个async修饰的函数 async返回的promise的状态由await修饰的promise的状态决定 如果await修饰的promi
阅读全文
摘要:package.json项目描述文件,记录了当前项目信息,例如项目名称、版本、作者、github地址、当前项目依赖了哪些第三方模块等。 使用npm init-y命令生成。 记录了依赖模块,项目名称,版本号,程序入口,开发时依赖,简写命令等 { "dependencies": { "bluebird"
阅读全文
摘要:nodemon nodemon app.js 源码更改就重新运行 nrm nrm ls nrm use *** 更改npm下载地址 gulp 构建工具
阅读全文
摘要:先安装 bluebird npm install bluebird 使用promisifyAll函数,可以将模块导出的接口promise化,注意处理后的API函数名加Async如:fs.readFileAsync() var Promise = require('bluebird') const f
阅读全文
摘要://此时是等价的 exports.name = 'xxx' module.exports.sex = '男' //此时把module.export指向的对象改变,以module.exports为准 module.exports = { id:'1', girlfriend:{ name:'yyy'
阅读全文