教程:https://github.com/alsotang/node-lessons

0

nvm 的全称是 Node Version Manager,之所以需要这个工具,是因为 Node.js 的各种特性都没有稳定下来,所以我们经常由于老项目或尝新的原因,需要切换各种版本。

安装:$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash

安装node:nvm install 0.12

查看:nvm ls

1

查看该项目安装的模块

ls node_modules

或者npm list,这是全局的,有一定的结构

2

npm init初始化,会生成一份简单地package.json

npm install express utility --save  可以一次安装两个模块,--才是保存

utility包含了很多辅助方法,而crypto只是单独做加密的;

3爬虫

superagent:http 方面的库,可以发起 get 或 post 请求

好好看看 superagent 的 API,它把链式调用的风格玩到了极致

4并发

eventproxy 没接触过

5async

async demo:https://github.com/alsotang/async_demo

可以控制并发数:mapLimit; queue

这节写的真好。

5测试

require.main === module:   // 如果是直接执行 main.js,则进入此处   // 如果 main.js 被其他文件 require,则此处不会执行。

mian.text 不能引入 main?  同级的话require('./main');

执行测试:mocha main.test

var main = require('./main');
var should = require('should'); describe('main.test.js', function(){
it('should equal 55 when n === 10', function(){
main.fibonacci(10).should.equal(55);
})
})

describe 中的字符串,用来描述你要测的主体是什么;it 当中,描述具体的 case 内容。

mocha 测试库

should 断言库

expect 断言库

这就是传说中的测试驱动开发:先把要达到的目的都描述清楚,然后让现有的程序跑不过 case,再修补程序,让 case 通过。

istanbul 覆盖率

打开看看:open coverage/lcov-report/index.html  也可以直接打开页面

makefile:http://blog.csdn.net/haoel/article/details/2886

10 benchmark

nodejs的性能测试,和jsPerf结合使用

https://github.com/bestiejs/benchmark.js

http://jsperf.com

11 闭包

node 有一个全局对象global;浏览器全局对象window

sublimelinter没有正常使用

闭包:内部函数可以访问定义在外部函数中的变量。现在学习主要是为了使用,所以看一个知识点,一定要知道有什么用

var adder = function (x) {
var base = x;
return function (n) {
return n + base;
};
}; var add10 = adder(10);
console.log(add10(5)); var add20 = adder(20);
console.log(add20(5));

闭包的坑:不是每一种for循环的代码,都会碰到这个坑,而是里面的代码如果是异步或过一会才执行的话,就需要(idx)(i)了

14 最佳实践

在 js 中,务必使用 === 三个等于号来比较对象,或者自定义方法来比较,不要使用 ==。

我最近做一个项目,从数据库中取出的数据,虽然应该是字符型的,但有时它们是 String 的表示,有时是 Number 的表示。为了省事,会有人直接用 == 来对它们进行比较。这种时候,建议在比较时,把它们都转成 String 类型,然后用 === 来比较。

比如 var x = 31243; var y = '31243',比较时,这么做:String(x) === String(y)

lodash:https://lodash.com/docs  js的工具库  http://www.cnblogs.com/Leo_wl/p/4418781.html

node-lessons的更多相关文章

  1. babeljs源码

    babel.min.js!function(e,t){"object"==typeof exports&&"object"==typeof mo ...

  2. 如何搭建 node,react 开发环境

    项目相关内容:Sublime + Node + React --注意:在 windows 操作系统中,如果把 node 安装在系统盘(一般是C盘),会导致 node 没有操作文件的权限的问题,如无法新 ...

  3. [Whole Web] [Node.js] Using npm run to launch local scripts

    npm run allows you to configure scripts inside of your package.json file which can access locally in ...

  4. [Node.js] Using npm link to use node modules that are "in progress"

    It is some times convenient, even necessary, to make use of a module that you are working on before ...

  5. [Server Running] [Node.js, PM2] Using PM2 To Keep Your Node Apps Alive

    PM2 is a production process manager for Node.js applications with a built-in load balancer. It allow ...

  6. Codeforces 915E Physical Education Lessons

    原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...

  7. 【题解】Luogu CF915E Physical Education Lessons

    原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...

  8. Codeforces 915 E Physical Education Lessons

    题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...

  9. How do I get started with Node.js

    From: http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js Tutorials NodeSch ...

  10. [AngularFire2] Build a Custom Node Backend Using Firebase Queue

    In this lesson we are going to learn how to build a custom Node process for batch processing of Fire ...

随机推荐

  1. PAT 1038 统计同成绩学生(20)(代码)

    1038 统计同成绩学生(20)(20 分) 本题要求读入N名学生的成绩,将获得某一给定分数的学生人数输出. 输入格式: 输入在第1行给出不超过10^5^的正整数N,即学生总人数.随后1行给出N名学生 ...

  2. Openflow的架构+源码剖析 转载

    Openvswitch的架构网上有如下的图表示: Openvswitch原理与代码分析(1):总体架构 Openvswitch原理与代码分析(2): ovs-vswitchd的启动 Openvswit ...

  3. NC 6系初始化EJB

    6系开发时,调用远程接口去操作数据时,需先调用EJB. InvocationInfoProxy.getInstance().setUserDataSource(design); InvocationI ...

  4. map reduce 用法 str处理lower() capitalize()

    -- s=' l={':9}[s[0]] print(l) 取出dic里面key的元素 def normalize(name): tempn=name.lower().capitalize() ret ...

  5. [Robot Framework] 学习资料

    https://www.cnblogs.com/pachongshangdexuebi/category/981644.html Robot Framework学习笔记(一)------环境搭建 Ro ...

  6. 1.about

    1)about Evarobot a.Evarobot Tech Specs 2)应用场景 Using a PC running visualisation/monitoring software a ...

  7. Tomcat优化详细1

    在Tomcat和应用程序进行了压力测试后,如果您对应用程序的性能结果不太满意,就可以采取一些性能调整措施了,当然了前提是应用程序没有问题,我们这里只讲Tomcat的调整.由于Tomcat的运行依赖于J ...

  8. Python中的实例方法、类方法、静态方法和普通方法

    为了辨析它们的差别,写了如下代码: class C: def self_method(self, a): return a @classmethod def class_method(cls, a): ...

  9. Tomcat新问题 还没有解决:the apr based apache tomcat native librariy which allows optional perf...........

     问题信息详细: 2012-5-18 18:41:54 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apa ...

  10. (转)用webbrowser做的网站登陆程序,如何获取cookie并且保存在程序中 (IE8有效) ,用途嘛,你懂的。

    今天帮朋友做了个工具,用webbrowser做的,用户使用用户名密码登陆网站后,需要在后台下载和分析一些页面. 分析页面使用的是htmlparser .net版 里面唯一需要解决的问题是,登陆后的co ...