node.js中的DIRT程序
来源:互联网 发布:苏州大学网络教育 编辑:程序博客网 时间:2024/06/11 08:19
DIRT
data-intensive real-time:数据密集型实时程序。
package.json总是被放在程序的根目录下。package.json用于描述你的应用程序
创建模块
模块既可以是一个文件,也可以是包含一个或者多个文件的目录。如果模块是目录,Node通常会在这个目录下找一个index.js的文件作为模块的入口。
用module.exports微调模块的创建
尽管用函数和变量组装exports对象能满足大多数的模块创建需要,但是有时可能需要不同的模型创建该模块。
如有时候只返回一个构造函数,而不是包含2个函数的对象,面向对象的实现看起来:
var Currency =require('./currency');var CanadianDollar=0.91;var currency=new Currency(canadianDollar);consoloe.log(currency.canadianToUs(50));
Node不允许把任何其他对象、函数、变量给exports赋值。
如:
var Currency=function(canadianDollar){ this.canadianDollar=canadianDollar; } Currency.prototype.roundTwoDecimals=function(amount){ return Math.round(amount*100)/100;} Currency.prototype.canadianToUS=function(canadian){ return this.roundTwoDecimals(canadian*this.canadianDollar); ... } exports=Currency;
回调
回调是一个函数,它被当做参数传给异步函数,它描述了异步操作完成之后要做什么。
阅读全文
0 0
- node.js中的DIRT程序
- Node.js中的IOCP
- node.js中的require
- Node.js中的模块
- node.js中的models
- Node.js 中的copy
- node.js中的控制台
- Node.js中的路径
- Node,js 中的Promise
- Node.js 中的模块
- Node.js中的模块
- node.js中的文件系统
- node.js中的exports
- node.js中的Stream
- node.js中的path;
- node.js中的response
- 利用node-inspector 调试node.js程序
- Node Inspector 调试 Node.js 程序
- 电脑显示内存不足的处理方法
- 半年总结
- what is signal?
- 【POJ】3685
- StringBuilder在高性能场景下的正确用法
- node.js中的DIRT程序
- Android面试题1
- CodeForces
- [Android]BroadcastQueue如何分发广播(四)
- 通过Amazon EC2来搭建基于pptpd协议的服务器
- JavaScript模块化 --- Commonjs、AMD、CMD、es6 modules
- 04:谁拿了最多奖学金
- 多例设计模式
- Linux驱动学习(2)