随笔分类 -  Node.js

摘要:源码如下:exports是最终还是通过module.exports将文件模块的方法和属性暴露给require返回的对象进行调用 可以简单理解为exports是在给module.exports添加属性和方法 阅读全文
posted @ 2016-07-05 17:08 DeadGhost 阅读(143) 评论(0) 推荐(0)
摘要:一、http对象的属性和方法 1、http.STATUS_CODES //A collection of all the standard HTTP response status codes, and the short description of each 2、http.METHODS //A 阅读全文
posted @ 2016-07-01 21:52 DeadGhost 阅读(285) 评论(0) 推荐(0)
摘要:一、对象方法 querystring.parse(str[, sep[, eq[, options]]]) //将一个 query string 反序列化为一个对象。可以选择是否覆盖默认的分割符('&')和分配符('=')。 querystring.stringify(obj[, sep[, eq[ 阅读全文
posted @ 2016-06-28 21:28 DeadGhost 阅读(221) 评论(0) 推荐(0)
摘要:一、Url组件 二、Url对象 objURL=url.parse(urlStr,[parseQueryString],[slasheDenoteHost]) 将第二个参数设置为 true 则使用 querystring 模块来解析 URL 中的查询字符串部分,默认为 false。 将第三个参数设置为 阅读全文
posted @ 2016-06-28 20:18 DeadGhost 阅读(127) 评论(0) 推荐(0)
摘要:一、处理JSON 1、将JavaScript数据转换为JSON对象(序列化) JSON.stringify(Object) 2、将JSON数据转换为JavaScript对象(逆序列化) JSON.parse(stringJSON) 二、Buffer模块缓冲数据(使用两位16进制表示一字节) 1、创建 阅读全文
posted @ 2016-06-27 18:30 DeadGhost 阅读(208) 评论(0) 推荐(0)
摘要:一、打开和关闭文件 //在不同的操作系统中表现有所不同 var fd=fs.open(path,flags,[mode],callback) //返回一个整型 表示打开的文件对象 fs.close(fd,callback) 附:flags参数表,表示打开文件的模式 'r' - Open file f 阅读全文
posted @ 2016-06-26 19:55 DeadGhost 阅读(552) 评论(0) 推荐(0)
摘要:一、循环模块 1、当存在循环的require()调用时,一个模块可能在返回时并不会被执行。 //只在第一次调用时会执行 二、核心模块 1、Node中有一些模块是编译成二进制的。 2、核心模块定义在node源代码的lib/目录下。 3、require()总是会优先加载核心模块。例如,require(' 阅读全文
posted @ 2016-06-24 15:09 DeadGhost 阅读(309) 评论(0) 推荐(0)
摘要:一、EventEmitter类 1、描述:EventEmitter是Events模块定义的一个类,所有事件对象都是该类的实例 2、创建EventEmitter对象 直接创建: (推荐)继承EventEmitter类,然后创建 3、两种创建方法的区别: 子类继承Object类:class A exte 阅读全文
posted @ 2016-06-13 20:58 DeadGhost 阅读(531) 评论(0) 推荐(0)
摘要:1、创建相应项目文件(或进入该项目文件根目录) 2、安装模块 npm install <Module> 3、使用require()方法 require("moduleName"); 4、测试如下: a、创建模块ModuleB,生成.tgz文件(npm pack) b、安装ModuleB模块(npm 阅读全文
posted @ 2016-06-12 22:33 DeadGhost 阅读(195) 评论(0) 推荐(0)
摘要:1、添加用户到环境中: npm adduser 2、设置package.json文件: ... "repository":{ "type":"git", "url":"https://......." }, "keywords":[...], ... 3、发布该模块 npm publish 4、删除 阅读全文
posted @ 2016-06-12 22:15 DeadGhost 阅读(363) 评论(0) 推荐(0)
摘要:指令 说明 name 包的唯一名字 preferGlobal 表示该模块更倾向于在全局范围内安装 version 该模块的版本 author 项目的作者 description 模块的文字说明 contributors 模块的其他贡献者 bin 随项目安装的二进制文件 scripts 启动Node时 阅读全文
posted @ 2016-06-12 21:57 DeadGhost 阅读(1692) 评论(0) 推荐(0)
摘要:以express模块为例: 命令 说明 示例 search 在存储中查找模块包 npm search express install 使用存贮库或本地位置上的一个package.json文件来安装模块 npm install/npm install express/npm install expre 阅读全文
posted @ 2016-06-12 21:05 DeadGhost 阅读(254) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2016-06-12 19:49 DeadGhost 阅读(126) 评论(0) 推荐(0)
摘要:一、console 二、exports 三、module 四、process 五、require() 1、require.cache 2、require.extensions //不赞成使用 3、require.resolve 六、定时器类 1、创建定时器 setImmediate(callback 阅读全文
posted @ 2016-06-11 20:58 DeadGhost 阅读(255) 评论(0) 推荐(0)
摘要:一、util.format(format[, ...]) 1、格式说明 %s - String. %d - Number (both integer and float). %j - JSON. Replaced with the string '[Circular]' if the argumen 阅读全文
posted @ 2016-05-20 13:24 DeadGhost 阅读(224) 评论(0) 推荐(0)
摘要:一、events.EventEmitter 1、All objects that emit events are instances of the EventEmitter class. (来自:https://nodejs.org/dist/latest-v6.x/docs/api/events. 阅读全文
posted @ 2016-05-20 13:23 DeadGhost 阅读(173) 评论(0) 推荐(0)