跳转到内容

Node.js

维基百科,自由的百科全书

这是本页的一个历史版本,由Audihsu留言 | 贡献2011年8月16日 (二) 09:10 建立内容为“{{infobox software | name = Node.js | logo = 150px|Node.js Logo | screenshot = | ca...”的新頁面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
Node.js
Node.js Logo
原作者Ryan Lienhart Dahl
開發者Node.js Developers
当前版本0.4.10(2011年7月19日 (2011-07-19)
预览版本0.5.4(2011年8月12日 (2011-08-12)
源代码库 編輯維基數據鏈接
编程语言C++, JavaScript
操作系统Mac OS X, Linux, Solaris, FreeBSD, OpenBSD, Windows (older versions require Cygwin), webOS
类型Event-driven networking
许可协议MIT License
网站http://nodejs.org/

Node.js is an event-driven I/O server-side JavaScript environment based on V8. It is intended for writing scalable network programs such as web servers.[1] It was created by Ryan Dahl in 2009, and its growth is sponsored by Joyent, which employs Dahl.[2] [3]

Similar environments written in other programming languages include Twisted for Python, Perl Object Environment for Perl, libevent for C and EventMachine for Ruby. Unlike most JavaScript, it is not executed in a web browser, but is instead a form of server-side JavaScript. Node.js implements some CommonJS specifications.[4] Node.js includes a REPL environment for interactive testing.

Examples

HTTP Server version of hello world in Node.js:

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World\n');
}).listen(8000);

console.log('Server running at http://127.0.0.1:8000/');

Another example with a simple TCP server which listens on port 7000 and echoes whatever you send it:

var net = require('net');

net.createServer(function (stream) {
    stream.write('hello\r\n');

    stream.on('end', function () {
        stream.end('goodbye\r\n');
    });

    stream.pipe(stream);
}).listen(7000);

Modules

Community

There is a very active Node.js developer community primarily centered on two mailing lists, nodejs and nodejs-dev, and the IRC channel #node.js on freenode. The community gathers at an NodeConf, an annual developer conference focused on Node.js.[5]

See also

References