node-lessons
教程: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的更多相关文章
- babeljs源码
babel.min.js!function(e,t){"object"==typeof exports&&"object"==typeof mo ...
- 如何搭建 node,react 开发环境
项目相关内容:Sublime + Node + React --注意:在 windows 操作系统中,如果把 node 安装在系统盘(一般是C盘),会导致 node 没有操作文件的权限的问题,如无法新 ...
- [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 ...
- [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 ...
- [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 ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- 【题解】Luogu CF915E Physical Education Lessons
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
- How do I get started with Node.js
From: http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js Tutorials NodeSch ...
- [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 ...
随机推荐
- PAT 1049 数列的片段和(20)(代码+思路分析)
1049 数列的片段和(20)(20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2 ...
- vxlan vs GRE(三层组播和二层组播如何对应起来)
www.huawei.com/ilink/cnenterprise/download/HW_401028 http://feisky.xyz/sdn/basic/vxlan.html 华为的vxlan ...
- iOS.Location-Based Service
基于位置区域的服务 1. 背景 Ref[1] 在iOS设备锁屏的状态下,App的icon会出现在屏幕的左下角. iOS 8 Feature: Location-based Lockscreen App ...
- Codeforces559C Gerald and Giant Chess
一道计数类\(DP\) 原题链接 我们可以先计算从左上角到右下角总的路径,再减去经过黑色方格的路径即是答案. 总路径数可以用组合数直接计算:\(C_{H+W-2}^{H-1}\) 因为从左上角到右下角 ...
- swift 属性值变化
如果创建了一个结构体的实例并将其赋值给一个常量,则无法修改该实例的任何属性,即使有属性被声明为变量也不行. 这种行为是由于结构体(struct)属于值类型.当值类型的实例被声明为常量的时候,它的所有属 ...
- js,jquery的数字型字符串变量比较大小
转:http://blog.csdn.net/dxnn520/article/details/8267173 var定义的变量应该是字符串,有时没有经过类型转换而进行比较的话,小于十的话还可以,如果大 ...
- PreparedStatement批量处理和事务
PreparedStatement批量处理和事务代码如下: /* * PreparedStatement: 1.addBatch() 将一组参数添加到 PreparedStatement对象内部 2. ...
- 利用PHP脚本辅助MySQL数据库管理4-两个库表结构差异比较
<?php define('DATABASE1', 'coffeetest'); $dbi1 = new DbMysql; $dbi1->dbh = 'mysql://root:mysql ...
- Ajax在jQuery中的应用 (4)向jsp提交表单数据
ajax技术带给我们的是良好的用户体验,同时,使用jquery可以简化开发,提高工作效率. 下面就介绍一下大致的开发步骤. 工具/原料 本文中使用的是 jquery-1.3.2.min.js 方法/步 ...
- 视频基础知识:浅谈视频会议中H.264编码标准的技术发展
浅谈视频会议中H.264编码标准的技术发展 浅谈视频会议中H.264编码标准的技术发展 数字视频技术广泛应用于通信.计算机.广播电视等领域,带来了会议电视.可视电话及数字电视.媒体存储等一系列应用,促 ...