Node.js v0.8 即将发布
openkk 12年前
<a href="http://www.open-open.com/lib/view/open1338390222073.html" target="_blank">Node.js</a>是一套用来编写高性能网络服务器的JavaScript工具包,一系列的变化由此开始。比较独特的是,Node.js会假设你是在POSIX环境下运行它Linux 或 Mac OS X。如果你是在Windows下,那就需要安装MinGW以获得一个仿POSIX的环境。在Node中,Http是首要的。Node为创建http服务器作了优化,所以你在网上看到的大部分示例和库都是集中在web上(http框架、模板库等)。 <br /> <br /> <p><strong>Node.js v0.8</strong> 版本指日可待了,0.7 版本再经过1个或者2个版本发布就转为稳定版了。</p> <p><strong>NodeJS v0.6</strong> 和 <strong>Node.js v0.8</strong> 在 API 上有一些小变化。</p> <h2 id="deprecated">废弃:</h2> <ul> <li><code>http.Client()</code></li> <li><code>path.{exists,existsSync}</code> was moved to <code>fs.{exists,existsSync}</code></li> <li><code>tty.setRawMode(mode)</code> was moved to <code>tty.ReadStream#setRawMode()</code> (i.e. <code>process.stdin.setRawMode()</code>)</li> </ul> <h2 id="removed">删除:</h2> <ul> <li><code>waf</code> build system - <code>node.js</code> will be using <code>gyp</code> now * If you are a native module author, migrate to <a href="/misc/goto?guid=4958343045341119651"><code>node-gyp</code></a> ASAP!</li> <li><code>sys</code> throws</li> </ul> <h2 id="changed">改动:</h2> <ul> <li> <p><code>process</code> * <code>process.stdin.on('keypress')</code> will not be emitted by default, as it’s an internal API.</p> </li> <li> <p><code>cluster</code></p> <ul> <li><code>cluster.fork()</code> no longer return a <code>child_process.fork()</code> object use <code>cluster.fork().process</code> to get the object.</li> <li>the <code>'death'</code> event on the <code>cluster</code> object is renamed to <code>'exit'</code>.</li> <li>the <code>kill()</code> method is renamed to <code>destroy()</code>.</li> <li>the <code>CLUSTER_WORKER_ID</code> env is now called <code>CLUSTER_UNIQUE_ID</code>, but you should not have used that anyway.</li> <li>workers do now kill them self when they accidentally losses there connection with the master.</li> </ul> </li> <li> <p><code>http</code></p> <ul> <li><code>http.Server</code> emits <code>'connect'</code> event instead of <code>'upgrade'</code> when the CONNECT method is requested.</li> <li><code>http.ServerResponse</code> sends <code>Date:</code> header by default. You can disable it by setting <code>response.sendDate</code> to <code>false</code>.</li> <li><code>http.ClientRequest</code> emits <code>'connect'</code> event instead of <code>'request'</code> when the CONNECT method is responded.</li> </ul> </li> <li> <p><code>child_process</code></p> <ul> <li><code>arguments</code> and <code>options</code> arguments of <code>child_process.fork()</code> became an option.</li> <li>the ‘exit’ event is now emitted right after the child process exits. It no longer waits for all stdio pipes to be closed.</li> <li>the ‘close’ event was added that has is emitted after the child has exited <em>and</em> all the stdio pipes are closed.</li> </ul> </li> <li> <p><code>readline</code> * <code>arguments</code> of <code>rl.createInterface</code> became an option as <code>rl.createInterface(options)</code> but still took an old style as rl.createInterface(input, output, completer)</p> </li> <li> <p><code>url</code> * <code>url.parse()</code> now parses IPv6 addresses.</p> </li> <li> <p><code>fs</code> * <code>path.exists()</code> and <code>path.existsSync()</code> has moved to <code>fs.exists()</code> and <code>fs.existsSync()</code>.</p> </li> <li> <p><code>console</code> * <code>console.timeEnd</code> now throws when there’s no such label</p> </li> </ul> <h2 id="added">添加:</h2> <ul> <li> <p><code>buffer</code> * <code>'utf16le'</code> encoding.</p> </li> <li> <p><code>child_process</code></p> <ul> <li><code>silent</code> option to <code>child_process.fork()</code> - <code>stdout</code> and <code>stderr</code> won’t be shared with parent.</li> <li><code>.disconnect()</code> when using <code>child_process.fork()</code> this will allow the child to die graceful.</li> </ul> </li> <li> <p><code>cluster</code></p> <ul> <li><code>'fork'</code>, <code>'online'</code>, <code>'listening'</code>, and <code>'setup'</code> events.</li> <li><code>Worker</code> object which is provided from <code>cluster.workers</code> (in the master) or <code>cluster.worker</code> (in the worker).</li> <li><code>env</code> optional argument to <code>cluster.fork()</code>.</li> <li><code>cluster.setupMaster()</code> and <code>cluster.settings</code>.</li> <li><code>cluster.disconnect()</code> and <code>worker.disconnect()</code>.</li> <li><code>worker.uniqueID</code> what there before was internally known as <code>workerID</code>.</li> <li><code>worker.suicide</code> flag set when worker disconnect or die, indicate if this was an accidental death.</li> </ul> </li> <li> <p><code>crypto</code></p> <ul> <li><code>crypto.getDiffieHellman()</code>.</li> <li><code>cipher.setAutoPadding()</code> and <code>decipher.setAutoPadding()</code>.</li> <li><code>ciphers</code> option to <code>crypto.createCredentials()</code>.</li> </ul> </li> <li> <p><code>domain</code> * see http://nodejs.org/docs/v0.7.9/api/domain.html</p> </li> <li> <p><code>fs</code></p> <ul> <li><code>fs.appendFile()</code> and <code>fs.appendFileSync()</code>.</li> <li><code>wx</code>, <code>wx+</code>, <code>ax</code>, and <code>ax+</code> modes to <code>fs.open()</code> and <code>fs.openSync()</code>.</li> </ul> </li> <li> <p><code>http</code></p> <ul> <li>callback optional argument to <code>server.close()</code>.</li> <li><code>sendDate</code> property to <code>http.ServerResponse</code>.</li> </ul> </li> <li> <p><code>https</code> * <code>ciphers</code>, <code>rejectUnauthorized</code> option to <code>https.request()</code> and <code>https.get()</code>.</p> </li> <li> <p><code>net</code></p> <ul> <li><code>net.connect(options, [connectionListener)</code>.</li> <li>callback optional argument to <code>server.close()</code>.</li> </ul> </li> <li> <p><code>process</code></p> <ul> <li><code>process.abort()</code>.</li> <li><code>process.hrtime()</code>, hi-res timer with up to nanosecond granularity.</li> </ul> </li> <li> <p><code>querystring</code> * <code>querystring.parse(str, [sep], [eq], [options])</code>.</p> </li> <li> <p><code>stream</code> * <code>'utf16le'</code> and <code>'ucs2'</code> encoding to <code>setEncoding()</code>.</p> </li> <li> <p><code>tls</code></p> <ul> <li><code>tls.CLIENT_RENEG_LIMIT</code> and <code>tls.CLIENT_RENEG_WINDOW</code> to <a href="/misc/goto?guid=4958343046151298690">mitigate session renegotiation attacks</a></li> <li><code>tls.connect(options, [secureConnectionListener])</code>.</li> <li><code>ciphers</code>, <code>rejectUnauthorized</code> and <code>socket</code> options to <code>tls.connect()</code>.</li> <li><code>cleartextStream.getCipher()</code> was added in the api doc and open to the public.</li> </ul> </li> <li> <p><code>zlib</code> * <code>dictionary</code> option.</p> </li> </ul>