node. JS v4.4.7 Documentation (Official document)
Buffer
Prior TypedArray
to the introduction of ECMAScript (ES6), the JavaScript language had no mechanism for reading or Manip ulating streams of binary data (binary). The class is introduced as part of the Buffer
node. js API to make it possible to interact with octet streams in the Contex T of things like TCP streams and file system operations.
Url
This module has a utilities for URL resolution (URL resolution) and parsing. Call require(‘url‘)
-to-use it.
URL (global resource Locator (Uniform Resource Locator)) URL parsing
Url.parse () returns the object
parsed URL Objects has some or all of the following fields, depending on whether or not they exist in the URL St Ring. Any parts that is not in the URL string is not being in the parsed object.
URL {
Protocol: ' http: ',//protocol
Slashes:true,//whether there is a slash
Auth:null,
Host: ' jingyan.baidu.com ',//hostname including port information (including port)
Port:null,//Port
Hostname: ' jingyan.baidu.com ',//host Domain
Hash:null,//hash, anchor
Search:null,
Query:null,
Pathname: '/article/93f9803fd3a4dde0e46f55f5.html ',//
Path: '/article/93f9803fd3a4dde0e46f55f5.html ',//concatenation ofpathname
andsearch
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.
Returns a URL string
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 of string, and return an object.
Pass as the true
second argument to also parse the query string using querystring
the module (node. JS built-in query string module ) . If then the property is always being true
query
assigned an object, and the property is always search
a (poss ibly empty) string. If then the property is not being false
query
parsed or decoded. Defaults to false
.
Query String
This module provides utilities -dealing with query strings (query string processing)
Querystring.stringify (obj[, sep][, eq][, Options])
Serialize An object to a query string. Serializes an object into a query string
Optionally override the default separator ( ‘&‘
) and Assignment ( ‘=‘
) characters ( the delimiter is & =).
Querystring.parse (str[, sep][, eq][, Options])
Deserialize (deserialization) a query string to an object. Optionally override the default separator ( ‘&‘
) and Assignment ( ‘=‘
) characters.
Querystring.escape Querystring.unescape
Querystring.escape Escape
Querystring.unescape Reversal Righteousness
File System
File I/O is provided-wrappers around standard POSIX functions. To use the This module does require(‘fs‘)
. all the methods has asynchronous and synchronous forms (both have asynchronous and synchronous formats).
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 and then the raw buffer is returned.
HTTP
To use the HTTP serverand client (server side and Clients ), one must require(‘http‘)
.
The HTTP interfaces in node. JS is designed to support many features of the protocol which has 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 was able to stream data.
Http.request (options[, callback])
options
Can is an object or a string (object or String). If options
is a string, it's automatically parsed with url.parse()
.
The optional callback
parameter is added as a one time listener for the ‘response‘
event.
Http.get (options[, callback])
Since Most requests is GET requests without bodies, node. JS provides this convenience method. the only difference (the difference from the request) between this method, and is, http.request()
it sets the method to GET and calls req.end()
automatically.
EVENT
In layman's node. JS (iv): node. js event mechanism
Much of the node. JS Core API is built around a 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 this emit events EventEmitter
is instances of the class ( an instance of Eventemitter ). These objects expose an eventEmitter.on()
function ( these objects (emitter) are exposed. The On () method, which allows adding some listeners (function)) thatallows one or More Functions to is attached to named events emitted by the object.
eventEmitter.on()
The method is used to register listeners (registered listener), while the eventEmitter.emit()
method is used to trigger the event (excitation Event).
The event module (Events.eventemitter) is an implementation of a simple incident listener pattern. The method realizes the basic event listening mode such as 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 if true
the event had listeners (if there is a listener), 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
.
node. js API