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 ...
随机推荐
- RDMA的基础概念
一张图可以简单明确的说明,目前RDMA的几种技术的差别: RDMA是remote Direct memory access的简称,有几个最基本的特点: CPU offload kernel bypas ...
- AFNetworking HTTP响应头返回数据
//发送验证码 NSLog(@"发送验证码"); AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationM ...
- 20172325『Java程序设计』课程 结对编程练习_四则运算第三周阶段总结
20172325『Java程序设计』课程 结对编程练习_四则运算第三周阶段总结 结对伙伴 学号:20172306 姓名:刘辰 在这次项目的完成过程中刘辰同学付出了很多,在代码的实践上完成的很出色,在技 ...
- PHP 批量移动文件改名
public function changeCoverName(){ //$type = '考研'; //$coverPath = './Public/course_cover/kaoyan/'; $ ...
- .core 学习文档
https://docs.microsoft.com/zh-cn/aspnet/core/razor-pages/?view=aspnetcore-2.1&tabs=visual-studio
- go语言字符串练习
package main import "fmt" import s"strings" var p = fmt.Println func main() { p( ...
- 如何上传Packages到PyPI并批量抓取
1.如何上传包到PyPI ? 更新中... 2.批量抓取simple网站第三方模块 https://pypi.python.org/simple/ 3. 第三方模块的安装和使用 python set ...
- RAID : 独立磁盘冗余阵列(Redundant Array of Independent Disks)
RAID 分为不用的等级(RAID0 - RAID5),以满足不同的数据应用需求. RAID 是由多个独立的高性能磁盘驱动器组成的磁盘子系统,从而提供比单个磁盘更高的存储性能和数据冗余的技术. AID ...
- iOS知识基础篇--@property,@synthesize, nonatomic,atomic,strong,weak,copy,assign,retain详解
一.@property 这个关键词的唯一作用就是声明getter.setter方法接口. 二.@synthesize 实现setter.getter方法,找不到实例变量则主动创建一个. 三.nonat ...
- Linux关机操作
正确的关机流程为:sync > shutdown > reboot > halt 关机指令为:shutdown ,你可以man shutdown 来看一下帮助文档. 例如你可以运行如 ...