景灵

——我要我想要的


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

删除Mac中的云梯配置

发表于 Mar 15 2015   |   分类于 工具

删除Mac中的云梯配置:
http://hcleon.iteye.com/blog/2177574

mongodb简单学习

发表于 Mar 15 2015   |   分类于 mongodb

MongoDB的内部构造 From 《MongoDB The Definitive Guide》
http://www.cnblogs.com/gpcuster/archive/2010/10/04/1841877.html
MongoDB——通过客户端理解mongoDB体系结构
http://blog.csdn.net/liusong0605/article/details/10611895
MongoDB内存使用原理
http://www.searchdatabase.com.cn/showcontent_51990.htm


  1. 日期:mongodb的日期不包含时区。日期对象 new Date(),日期字符串 Date(…)

  2. json仅包含6中数据类型:(null,布尔,数字,字符串,数组,对象)
    局限:

    1)没有日期类型
    2)只有一种数字类型,无法区分浮点数和整数,更别说区分32位和64位数字
    3)不能表示其他通用类型,比如,正则表达式
    
  3. BSON:

    阅读全文 »

mongodb和redis设计原理简析

发表于 Mar 15 2015   |   分类于 mongodb

来源:http://blog.csdn.net/yangbutao/article/details/8309539

express4.x

发表于 Mar 14 2015   |   分类于 express
  1. Express.js 4.x 新功能

    • http://segmentfault.com/blog/gucheen/1190000000603325
  2. 解读express 4.x源码(1)

    • http://segmentfault.com/blog/insideyiqi/1190000000577149
  3. Express 4.x的特性和3.x的迁移

    • http://segmentfault.com/blog/yeelan0319/1190000000661018
  4. Express 4.x API

    • http://expressjs.com/4x/api.html

npm常用命令

发表于 Mar 14 2015
  1. 查询node模块是否存在

    1
    $ npm search indexName
  2. 设定安装模式(全局模式、当前应用)

    1
    $ npm set global=true
  3. 查看当前使用的安装模式

    1
    $ npm get global
  4. 安装Node模块

    1
    $ npm install moduleNames -g 全局安装
  5. 查看node模块的package.json文件夹

    1
    2
    3
    4
    5
    6
    7
    $ npm view moduleNames
    $ npm view moduleName labelName 要查看package.json文件夹下某个标签的内容
    ```<!--more-->
    3. 查看当前目录下已安装的node包
    ``` bash
    $ npm list
    $ npm list parseable=true 可以目录的形式来展现当前安装的所有node包
  6. 查看帮助命令

    1
    $ npm help
  7. 查看包的依赖关系

    1
    $ npm view moudleName dependencies
  8. 查看包的源文件地址

    1
    $ npm view moduleName repository.url
  9. 查看包所依赖的Node的版本

    1
    $ npm view moduleName engines
  10. 查看npm使用的所有文件夹

    1
    $npm help folders
  11. 用于更改包内容后进行重建

    1
    $ npm rebuild moduleName
  12. 检查包是否已经过时,此命令会列出所有已经过时的包,可以及时进行包的更新

    1
    $ npm outdated
  13. 更新node模块

    1
    $ npm update moduleName
  14. 卸载node模块

    1
    $ npm uninstall moudleName
  15. package.json文件结构说明

    1
    $ npm help json
  16. 发布一个npm包的时候,检验某个包名是否已存在

    1
    $ npm search packageName

Node.js入门学习

发表于 Mar 14 2015   |   分类于 Node.js

Node.js v0.10.18手册&文档 http://nodeapi.ucdok.com/#/api/
Node.js v0.12.0文档 https://nodejs.org/api/
Node.js入门经典系列学习 http://www.myexception.cn/javascript/1702369.html
Node入门 http://www.nodebeginner.org/index-zh-cn.html#handling-post-requests

  1. node.js是首个将异步大规模带到应用层面的平台;但是异步在流程控制中,业务表达并不适合自然语言的线性思维

  2. nodejs适合于数据密集型实时的web程序,DIRT

  3. node中,I/O几乎总是在主事件轮询之外进行,使得服务器可以一直处于高效并且随时能够做出响应的状态,就想NGINX一样

  4. 在node 的世界里有两种响应逻辑管理方式:回调和事件监听

    • 回调:通常用来定义一次性响应逻辑(数据库查询定义回调函数来处理查询结果)
    • 事件监听器:本质也是一个回调,不同的是它跟一个概念实体(事件)相关联。
      阅读全文 »

mongoose查询操作的高级应用

发表于 Mar 14 2015   |   分类于 mongoose

来源:http://my.oschina.net/antianlu/blog/290899?p=1

Node.js测试报错

发表于 Mar 14 2015   |   分类于 Node.js
1
2
Uncaught Error: ENOENT, open 'C:\Users\jingling\project\test\images\avatar.jpg'
at Error (native)

原因:

1
2
3
4
5
6
7
8
9
10
it('login success', function (done) {
request.put('/users/profile')
.attach('avatar','../test/images/avatar.jpg') //这里的文件地址不能用 ../,应该直接写成'test/images/avatar.jpg'
.expect(200,function(err,res){
console.log(res.body);
res.body.data.avatar.should.exists;
res.body.data.nick_name.should.equal(newUser.nick_name+'new');
done(err);
});
});

让人纠结的mongoose

发表于 Mar 14 2015   |   分类于 mongoose

var mongoose = require(‘mongoose’);
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var moment = require(‘moment’);
var postFind = require(‘mongoose-post-find’);
var mongooseHidden = require(“mongoose-hidden”)({ defaultHidden: {_id:true,__v:true} });
var stepSchema = new Schema({//加载图片
imgUrl: {
type: String,
required: true
},
timePoint: {//截止时间节点
type: Number
}
},{
id:false,
toObject: {getters: true},
toJSON: {getters: true}
});
//TODO:id及虚拟id的问题
var cardCommentSchema = new Schema({//卡片评论、回复

commentUser: {//评论者
    type: ObjectId,
    ref: 'UserV2',
    required: true
},
targetUser: {//评论对象
    type: ObjectId,
    ref: 'UserV2'
},
content: {//内容
    type: String,
    required: true
},
isReported: {//举报
    type: Boolean,
    default: false
},
createdAt: {
    type: Date,
    required: true,
    default: Date.now
}

},{
id:false,
toObject: {getters: true},
toJSON: {getters: true}
});
var cardSchema = new Schema({
owner: {//卡片作者
type: ObjectId,
ref: ‘UserV2’,
required: true
}, //own user id
title: {//标题
type: String,
required: true,
validate: function (val) {
return val.length <= 20;
}
},
description: {//描述
type: String,
default: ‘’
},
soundStory: {
type: String,
default: ‘’
},
steps: {//图片顺序及播放时间、
type: [stepSchema]
},
comments: {//评论
type: [cardCommentSchema]
},
playUsers: {//播放者
type: [ObjectId]
},
praiseUsers: {//收藏(点赞)者
type: [ObjectId]
},
downloadUsers: {//下载者
type: [ObjectId]
},
sharedUsers: {//分享者
type: [ObjectId]
},
reportUsers: {//举报者
type: [ObjectId]
},
color: {//颜色
type: String,
default: ‘’
},
isRecommended: {//推荐
stateType: {
type: String,
default: ‘undone’,
enum: [‘done’, ‘undone’, ‘waiting’]//推荐过,未被推荐过,等待被推荐
},
recommendAt: {
type: Date
}
},
createdAt: {
type: Date,
required: true,
default: Date.now
},
updatedAt: {
type: Date,
required: true,
default: Date.now
}
}, {
id:false,
toObject: {getters: true},
toJSON: {getters: true}
});
stepSchema.virtual(“stepId”).get(function(){
return this._id
});
cardCommentSchema.virtual(“commentId”).get(function(){
return this._id
});
cardSchema.virtual(“cardId”).get(function(){
return this._id
});
cardSchema.virtual(“commentCount”).get(function () {
return (this.comments && this.comments.length) || 0;
});
cardSchema.virtual(“downloadCount”).get(function () {
return (this.downloadUsers && this.downloadUsers.length) || 0;
});
cardSchema.virtual(“praiseCount”).get(function () {
return (this.praiseUsers && this.praiseUsers.length) || 0;
});
cardSchema.virtual(“sharedCount”).get(function () {
return (this.sharedUsers && this.sharedUsers.length) || 0;
});
cardSchema.virtual(“playCount”).get(function () {
return (this.playUsers && this.playUsers.length) || 0;
});
cardSchema.virtual(“isReported”).get(function () {
return (this.reportUsers && this.reportUsers.length) ? true : false;
});
cardSchema.virtual(“playCount”).get(function(){
return (this.playUsers&&this.playUsers.length)||0;
});
cardSchema.options.toObject.hide = ‘_id’;
cardSchema.options.toObject.transform = function (doc, ret, options) {
// remove the _id of every document before returning the result
delete ret._id;
};
stepSchema.options.toObject.transform = function (doc, ret, options) {
// remove the _id of every document before returning the result
delete ret._id;
};
//cardSchema.plugin(mongooseHidden);
//cardCommentSchema.plugin(mongooseHidden);
//stepSchema.plugin(mongooseHidden);
////cardSchema.plugin(require(‘mongoose-toobject’), { hide: ‘_id’ });
//var postFind = require(‘mongoose-post-find’);
//cardSchema.plugin(postFind, {
//
// find: function(results,done) {
// console.log(cardSchema.options);
// for(var i=0;i<results.length;i++){
// results[i]._doc.cardId = results[i]._id;
// delete results[i]._doc._id;
// delete results[i]._doc.v;
// for(var j=0;j< results[i].steps.length;j++){
// results[i].steps[j]._doc.stepId = results[i].steps[j]._doc._id;
// delete results[i].steps[j]._doc._id;
// }
// }
//
// done(null, results); //Results must be passed to callback
// },
// findOne: [
// function(result, done) {
// result._doc.cardId = result._id;
// delete result._doc._id;
// delete result._doc.
v;
// for(var j=0;j< result.steps.length;j++){
// result.steps[j]._doc.stepId = result.steps[j]._doc._id;
// delete result.steps[j]._doc._id;
// }
// done(null, result)
// }
// ]
//});

module.exports = cardSchema;

Node.js测试相关资料

发表于 Mar 14 2015   |   分类于 Node.js
  1. supertest

    • 中文
      • https://github.com/alsotang/node-lessons/tree/master/lesson8
    • 英文
      • https://github.com/visionmedia/supertest
    • 案例
  2. superagent

    • https://visionmedia.github.io/superagent/
  3. mocha

    • 英文:
      • http://mochajs.org/
    • 中文
      • https://mochacn.github.io/
      • https://cnodejs.org/topic/516526766d38277306c7d277
  4. should

    • API文档:
      • https://shouldjs.github.io/
    • 源码:
      • https://github.com/shouldjs/should.js
  5. API测试工具 Postman

1…5678
crazyjingling

crazyjingling

crazyjingling's blog | Node.js | javascript

75 日志
60 分类
106 标签
github twitter weibo zhihu
© 2016 crazyjingling
由 Hexo 强力驱动
主题 - NexT.Mist