Node.js v6.11.2  Documentation(官方文档)

Buffer

Prior to the introduction of TypedArray in ECMAScript 2015 (ES6), the JavaScript language had no mechanism for reading or manipulating streams of binary data(二进制数据). The Buffer class was introduced as part of the Node.js API to make it possible to interact with octet streams in the context of things like TCP streams and file system operations.

URL

This module has utilities for URL resolution(url解析) and parsing. Call require('url') to use it.

URL(全球资源定位器(Uniform Resource Locator))

URL Parsing

url.parse() 返回对象

Parsed URL objects have some or all of the following fields, depending on whether or not they exist in the URL string. Any parts that are not in the URL string will not be in the parsed object.

Url {
protocol: 'http:',   // 协议
slashes: true,      // 是否有斜线
auth: null,
host: 'jingyan.baidu.com',    //主机域名 including port information(包括端口)
port: null,                          //端口
hostname: 'jingyan.baidu.com',    //主机域名
hash: null,                          //哈希,锚
search: null,
query: null,
pathname: '/article/93f9803fd3a4dde0e46f55f5.html',                              // 
path: '/article/93f9803fd3a4dde0e46f55f5.html',                                 // Concatenation of pathname and search
href: 'http://jingyan.baidu.com/article/93f9803fd3a4dde0e46f55f5.html'   // The full URL

}

url.format(urlObj)

Take a parsed URL object, and return a formatted URL string.

返回一个url字符串

url.resolve(from, to)

url.resolve('/one/two/three', 'four')         // '/one/two/four'
url.resolve('http://example.com/', '/one') // 'http://example.com/one'
url.resolve('http://example.com/one', '/two') // 'http://example.com/two'

url.parse(urlStr[, parseQueryString][, slashesDenoteHost])

Take a URL string, and return an object.

Pass true as the second argument to also parse the query string using the querystring module(Node.js内置的Query String模块). If true then the query property will always be assigned an object, and the search property will always be a (possibly empty) string. If false then the query property will not be parsed or decoded. Defaults to false.

Query String

This module provides utilities for dealing with query strings(查询字符串处理)

querystring.stringify(obj[, sep][, eq][, options])

Serialize an object to a query string. 把一个对象序列化为一个查询字符串

Optionally override the default separator ('&') and assignment ('=') characters(默认的分隔符是 & =).

querystring.parse(str[, sep][, eq][, options])

Deserialize(反序列化) a query string to an object. Optionally override the default separator ('&') and assignment ('=') characters.

querystring.escape  querystring.unescape

querystring.escape   转义

querystring.unescape  反转义

File System

File I/O is provided by simple wrappers around standard POSIX functions. To use this module do require('fs'). All the methods have asynchronous and synchronous forms(都有异步和同步两种格式).

fs.readFile(file[, options], callback)

  • file       <String> filename
  • options  <Object> | <String>
    • encoding  <String> | <Null> default = null
    • flag      <String> default = 'r'
  • callback         <Function>

If no encoding is specified, then the raw buffer is returned.

HTTP

To use the HTTP server and client(服务器端和客户端), one must require('http').

The HTTP interfaces in Node.js are designed to support many features of the protocol which have been traditionally difficult to use. In particular, large, possibly chunk-encoded, messages. The interface is careful to never buffer entire requests or responses--the user is able to stream data.

http.request(options[, callback])

options can be an object or a string(对象或字符串). If options is a string, it is automatically parsed with url.parse().

The optional callback parameter will be added as a one time listener for the 'response' event.

http.get(options[, callback])

Since most requests are GET requests without bodies, Node.js provides this convenience method. The only difference(与request的区别) between this method and http.request() is that it sets the method to GET and calls req.end() automatically.

EVENT

深入浅出Node.js(四):Node.js的事件机制

Much of the Node.js core API is built around an idiomatic asynchronous event-driven architecture in which certain kinds of objects (called "emitters") periodically emit named events that cause Function objects ("listeners") to be called.

All objects that emit events are instances of the EventEmitter class(是EventEmitter的实例). These objects expose an eventEmitter.on() function(这些对象(emitter)暴露出来.on()方法,允许添加一些listeners(Function)) that allows one or more Functions to be attached to named events emitted by the object.

The eventEmitter.on() method is used to register listeners(注册监听器), while the eventEmitter.emit() method is used to trigger the event(激发事件).

Event模块(events.EventEmitter)是一个简单的事件监听器模式的实现。具有addListener/on,once,removeListener,removeAllListeners,emit等基本的事件监听模式的方法实现。

var EventEmitter = require('events');

emitter.addListener(eventName, listener)

Alias for emitter.on(eventName, listener).

emitter.emit(eventName[, arg1][, arg2][, ...])

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Returns true if the event had listeners(如果有监听), false otherwise.

emitter.listenerCount(eventName)

  • eventName <Value> The name of the event being listened for

Returns the number of listeners listening to the event named eventName.

emitter.listeners(eventName)

Returns a copy of the array of listeners for the event named eventName.

Path

The path module provides utilities(模块提供了关于文件路径和目录路径操作的工具方法) for working with file and directory paths.

Node.js API的更多相关文章

  1. Node.js API 初解读(一)

    Node.JS API 初解读 Version: NodeJs v6.2.0 一. Assert 1.简介 Assert模块主要用于断言.如果表达式不符合预期,就抛出一个错误. 该模块用于编写程序的单 ...

  2. Node.js API 初解读(三)

    目录 Node.JS API 初解读三 Node.JS API 初解读三 Version: NodeJs v6.2.0 一. DNS (Domain Name Server) [域名服务器] 1.简介 ...

  3. Node.js API快速入门

    Node.js API 快速入门 一.事件EventEmitter const EventEmitter = require('events'); class MyEmitter extends Ev ...

  4. node.js(API解读) - process (http://snoopyxdy.blog.163.com/blog/static/60117440201192841649337/)

    node.js(API解读) - process 2011-10-28 17:05:34|  分类: node |  标签:nodejs  nodejsprocess  node.jsprocess  ...

  5. Node.js API 初解读(二)

    四. Cluster 1.简介 在介绍 Cluster 之前.我们需要知道 node的 一些基本特性,比如说 都知道的 nodejs最大的特点就是单进程.无阻塞运行,并且是异步事件驱动的. 那么随之而 ...

  6. node.js api文档生成

    ApiDoc官网地址为:http://apidocjs.com/在Java中有Swagger及其升级版的Swagger2+Springfox自动生成接口管理文档.而在Node.js中则可以利用ApiD ...

  7. Node.js API学习笔记(一)

    此文章已经发表于本人博客. Terminal(终端) 说起这个使用过linux系统的兄台一般都会知道的,本人理解:类似Putty这些ssh工具通过 软件来实现远程控制主机,对于我们使用者来说,它会显示 ...

  8. Node.js API 学习笔记

    常用 API 学习笔记 url 函数 url.parse: 解析 url 地址 url.resolve: 向 url 地址添加或替换字段 url.format: 生成 url 地址 querystri ...

  9. Node.js api接口和SQL数据库关联

    数据库表创建 服务器环境配置.连接 .操作.数据库 API接口  原则:

随机推荐

  1. activity的android:name所指的Activity实现类的简写问题

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package=" ...

  2. shell脚本作为保证PHP脚本不挂掉的守护进程实例

    前几天开始跑一份数据名单,名单需要提供用户名.是否有手机号.是否有邮箱,用户名单我轻易的获取到了,但是,用户名单有2000w之多,并且去检测用户是否有手机号.是否有邮箱必须得通过一个对外开放的安全接口 ...

  3. Linux:用at和crontab调度作业

    一.有2种作业调度方式 1.突发性的,就是只运行作业一次而不是定期运行,使用at命令. 例如在进程A运行一段时间后关闭该进程. 2.定期运行,就是每隔一定的周期运行一次,使用crontab命令. 如每 ...

  4. 从零开始学C++之构造函数与析构函数(二):初始化列表(const和引用成员)、拷贝构造函数

    一.构造函数初始化列表 推荐在构造函数初始化列表中进行初始化 构造函数的执行分为两个阶段 初始化段 普通计算段 (一).对象成员及其初始化  C++ Code  1 2 3 4 5 6 7 8 9 1 ...

  5. Android 架构艺术之MVP

    MVP是Google官方发布的Android开发相关的架构知识.本文要讲解的是一种最基本的MVP的实现方式,它使用手动的依赖注入来提供具有本地和远程数据源的存储库.异步任务处理回调. 基本的MVP的项 ...

  6. Perception(0-1.1)

    The perception modules run in the context of the process Cognition. They detect features in the imag ...

  7. 读《不要告诉我你懂margin(海玉的博客)》有感

    原文来自海玉的博客:http://www.hicss.net/do-not-tell-me-you-understand-margin/ [个人想法] 1."这个问题发生的原因是根据规范,一 ...

  8. [UWP小白日记-8]一些零碎的东西

    设置启动窗口大小 直接上代码了没什么好解释的了,既然能设置最小,那铁定就能设置最大 public MainPage() { //设定窗口启动显示大小 ApplicationView.Preferred ...

  9. xtrabackup 开启压缩备份

    完整备份innobackupex --defaults-file=/etc/my.cnf --host=localhost --user=bkpuser --password=s3cret /data ...

  10. python——爬虫

    网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引.模拟程序或者蠕 ...