摘要: 返回Promise,成功则返回用户信息 const login = function (userModel,condition) { const rtn = new Promise((reslove, reject) => { userModel.find(condition, (err, docs 阅读全文
posted @ 2021-05-27 18:55 丁同亚的博客 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 目录结构 module db.js user.ja app.js db.js const mongoose = require('mongoose') mongoose.connect('mongodb://localhost/eg', { useNewUrlParser: true, useUni 阅读全文
posted @ 2021-05-27 18:41 丁同亚的博客 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 根据纲要(Schema)和dataBase中的集合(Collection)创建模型(Model) Schema(纲要):并没有实质性的操作集合,只是在程序中设定了一些规则,然后应用规则到数据库集合中来创建model. const userSchema= new mongoose.Schema({ / 阅读全文
posted @ 2021-05-24 10:24 丁同亚的博客 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 数据库的连接 const mongoose = require('mongoose') // 如果数据库(database)不存在就会创建 mongoose.connect('mongodb://localhost/eg', { useNewUrlParser: true, useUnifiedTo 阅读全文
posted @ 2021-05-23 19:30 丁同亚的博客 阅读(1997) 评论(0) 推荐(0) 编辑
摘要: async和await是解决异步编程问题的。 promise的then方法链式调用不够优雅 async 修饰的函数同步返回一个promise 使用await必须包裹一个async修饰的函数 async返回的promise的状态由await修饰的promise的状态决定 如果await修饰的promi 阅读全文
posted @ 2021-05-18 16:13 丁同亚的博客 阅读(65) 评论(0) 推荐(0) 编辑
摘要: package.json项目描述文件,记录了当前项目信息,例如项目名称、版本、作者、github地址、当前项目依赖了哪些第三方模块等。 使用npm init-y命令生成。 记录了依赖模块,项目名称,版本号,程序入口,开发时依赖,简写命令等 { "dependencies": { "bluebird" 阅读全文
posted @ 2021-05-16 18:54 丁同亚的博客 阅读(68) 评论(0) 推荐(0) 编辑
摘要: nodemon nodemon app.js 源码更改就重新运行 nrm nrm ls nrm use *** 更改npm下载地址 gulp 构建工具 阅读全文
posted @ 2021-05-16 18:34 丁同亚的博客 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 先安装 bluebird npm install bluebird 使用promisifyAll函数,可以将模块导出的接口promise化,注意处理后的API函数名加Async如:fs.readFileAsync() var Promise = require('bluebird') const f 阅读全文
posted @ 2021-05-16 14:01 丁同亚的博客 阅读(70) 评论(0) 推荐(0) 编辑
摘要: //此时是等价的 exports.name = 'xxx' module.exports.sex = '男' //此时把module.export指向的对象改变,以module.exports为准 module.exports = { id:'1', girlfriend:{ name:'yyy' 阅读全文
posted @ 2021-05-16 10:05 丁同亚的博客 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 浮动的影响 浮动的元素脱离文档流 浮动元素后面的兄弟元素就会占据原先它的位置 其父元素感知不到他的存在,撑不开父元素. 解决方法 在浮动元素后加一个块元素div2,添加clear:both属性,div2会清除div1浮动的影响,div2后面的元素和父元素也不会受到浮动的影响了 .clearfix:: 阅读全文
posted @ 2020-12-20 13:39 丁同亚的博客 阅读(104) 评论(0) 推荐(0) 编辑