io.js是nodejs的友好版的分支("friendly fork”)。它支持npm中全部的一样模块,且使用了v8最新版本的截取(v8是被node.js使用js解释器),且修复了不少的bug,下面咱们将讨论这些新特性:node
在运行程序以前的预加载模块redis
新的node/iojs二进制有一个新的CLI选项用于在运行程序以前预加载模型。npm
-r--要求模块在启动的时候预加载app
这对于 预加载项目日志和调试你电脑中的模块颇有用测试
例如:ui
// preload.js var myLogger = require('./myredislogger')('remotehost', 8678) console.log = function () { console.log.apply(console.log, arguments) myLogger.log.apply(myLogger.log, arguments) } console.error = function () { console.error.apply(console.error, arguments) myLogger.error.apply(myLogger.error, arguments) } > node -r preload.js server.js
代码设置高效的UID/GIDthis
在大对数的可移植操做系统接口(posix)系统上面,高效的uid/gid(euid/egid)是程序建立文件的全部者,且程序使用其进行access检查(access checks)。如今,这些检查和设置能够在io,js中经过代码实现,例以下例:spa
process.geteuid()
process.seteuid(id)
process.getegid()
process.setegid(id)
享受简单化的流创造操作系统
当你使用io.js穿件一个新地简单化的建立(simplified creation API),你不须要在留上面设置难懂的underscore方法。调试
var transform = new stream.Transform({ transform: function(chunk, encoding, next) { // sets this._transform under the hood }, flush: function(done) { // sets this._flush under the hood } });
使用dns.lookup()的'all'参数获取全部的DNS结果
如今在结局域名问题的时候,你能够获取全部的结果,而不是只是得到第一个或默认的结果。
dns.lookup('localhost', {all:true}, function (err, results) { console.log(results) // [ { address: '127.0.0.1', family: 4 }, // { address: '::1', family: 6 }, // { address: 'fe80::1', family: 6 } ] })
使用Buffer.indexOf()
这和string上面的indexOf()相似,除了对Buffers不能使用。
在书写二进制转换器的时候buffer颇有用。
assert.deepStrictEqual() 适用于更好的测试
The assert module commonly used in testing has a deepEqual() function which quite useful but use '==' and not '==='. assert.deepStrictEqual has the same deep recursive functionality but uses '==='.
原文连接:https://blog.xervo.io/fun-with-iojs-6-new-features