Jump to content

Node.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Ber (talk | contribs) at 20:07, 2 May 2014 (new preview version 0.11.13). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

node.js
Original author(s)Ryan Lienhart Dahl
Developer(s)Node.js Developers, Joyent, Github Contributors
Initial releaseMay 27, 2009 (2009-05-27)[1]
Stable release
0.10.28 / May 1, 2014 (2014-05-01)[2]
Preview release
0.11.13 / May 1, 2014 (2014-05-01)[3]
Repository
Written inC, C++, JavaScript
Operating systemMac OS X, Linux, Solaris, FreeBSD, OpenBSD, Windows (older versions require Cygwin), webOS
TypeEvent-driven networking
LicenseMIT
Websitenodejs.org

Node.js is a software platform for scalable server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on Mac OS X, Windows and Linux with no changes.

Node.js applications are designed to maximize throughput and efficiency, using non-blocking I/O and asynchronous events. Node.js applications run single-threaded, although Node.js uses multiple threads for file and network events. Node.js is commonly used for real time applications due to its asynchronous nature.

Node.js internally uses the Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. Node.js contains a built-in asynchronous i/o library for file, socket and HTTP communication. The HTTP and socket support allows Node.js to act as a web server without additional web server software such as Apache.

Overview

Ryan Dahl, the creator of Node.js, originally had the goal in mind of creating web sites with push capabilities as seen in web applications like Gmail. After trying solutions in several other programming languages he chose JavaScript because of the lack of an existing I/O API. This allowed him to define a convention of non-blocking, event-driven I/O.[4]

Similar environments written in other programming languages include Tornado and Twisted for Python; Perl Object Environment for Perl; libevent for C; Vert.x for Java, JavaScript, Groovy, Python and Ruby; Akka for Java and Scala; EventMachine for Ruby and vibe.d for D. Unlike most JavaScript programs, Node.js is not executed in a web browser, but instead as a server-side JavaScript application. Node.js implements some CommonJS specifications.[5] It also provides a REPL environment for interactive testing.

Architecture

There are four building blocks that constitute Node.js. First, Node.js encapsulates libuv to handle asynchronous events and Google’s V8 to provide a run-time for JavaScript. Libuv is what abstracts away all of the underlying network and file system functionality on both Windows and POSIX-based systems like Linux, Mac OS X and Unix. The core functionality of Node.js, modules like Assert, HTTP, Crypto, etc., reside in a core library written in JavaScript. The Node.js bindings, written in C++, provide the glue connecting these technologies to each other and to the operating system.

Community

Node.js has a developer community primarily centered on two mailing lists, nodejs,[6] nodejs-dev,[7] and the IRC channel #node.js on freenode. The community gathers at NodeConf,[8] an annual developer conference focused on Node.js.[9]

Node.js is currently used by a number of large companies including Groupon,[10] SAP,[11]LinkedIn,[12][13] Microsoft,[14][15] Yahoo!,[16] Walmart[17] and PayPal.[18]

History

Inspiration

Ryan Dahl, creator of Node.js

Node.js was created by Ryan Dahl starting in 2009. Its development and maintenance is sponsored by Joyent.[19] Dahl was inspired to create Node.js after seeing a file upload progress bar on Flickr. The browser did not know how much of the file had been uploaded and had to query the web server. Dahl wanted an easier way.[20] Ruby's Mongrel web server was another source of inspiration for Dahl.[21]

Originally Dahl had several failed projects in C, Lua, and Haskell, but when Google's V8 engine was released, Dahl began to examine JavaScript.[22]

Even though his original idea was non-blocking, he "backed out of that (a bit) in the module system and a few other areas," as it made loading external libraries troublesome.[23]

Versions

Node.js was first published by Dahl in 2011 and could only run on Linux. npm, a package manager for Node.js libraries, was introduced the same year.

In June 2011, Microsoft partnered with Joyent to help create a native Windows version of Node.js.[24] The first Node.js build to support Windows was released in July.

Recent events

On January 30, 2012 Dahl stepped aside, promoting coworker and npm creator Isaac Schlueter to the gatekeeper position. Dahl wrote on Google groups,

Now that the rewrite on top of libuv is largely complete, I am ceding my position as gatekeeper to Isaac Schlueter. Our energy will now be largely focused over the next few months on improving the third party module system experience including a website for browsing modules, a new addon build system, and binary installations from npm. Isaac is in the unique position to bridge the gap between core and external modules to ensure a pleasant experience. After three years of working on Node, this frees me up to work on research projects. I am still an employee at Joyent and will advise from the sidelines but I won't be involved in the day-to-day bug fixes. Isaac has final say over what makes it into the releases. Appeals for new features, changes, and bug fixes should now be directed at him.[25]

Dahl continues to work for Joyent and as an advisor for Node.js.[26]

On January 15, 2014 Schlueter announced he was making npm his main focus and Timothy J Fontaine would be Node.js' new project lead. Isaac wrote on the Node.js blog,

Over the last year, TJ Fontaine has become absolutely essential to the Node.js project. He's been building releases, managing the test bots, fixing nasty bugs and making decisions for the project with constant focus on the needs of our users. ... Anyone who's been close to the core project knows that he's been effectively leading the project for a while now, so we're making it official. Effective immediately, TJ Fontaine is the Node.js project lead. I will remain a Node.js core committer, and expect to continue to contribute to the project in that role. My primary focus, however, will be npm.[27]

The next day, January 16, 2014, Timothy J Fontaine made a followup post outlining the road ahead where he, among other things, mention bug fixing, performance tuning, staying up to date with V8 engine and tooling.[28]

Tools and IDEs

IDEs (editor, debugger, linter)

Online code editors

Runtimes and debuggers

Examples

This is an implementation of a "hello world" HTTP server 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://localhost:8000/');

The following code is a simple TCP server which listens on port 8000 and echoes 'hello' upon connection:

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(8000);

See also

References

  1. ^ https://github.com/joyent/node/tags?after=v0.0.4
  2. ^ [1]
  3. ^ [2]
  4. ^ Hughes-Croucher, Tom; Wilson, Mike (2012). Up and Running with Node.js. Up and Running (1st ed.). Sebastopol: O'Reilly. p. vii. ISBN 978-1-4493-9858-3. I was concerned about the ability to program advanced push features into the website like I had seen in Gmail
    See the book's Foreword at OReilly.com
  5. ^ Implementations/node.js - CommonJS Spec Wiki
  6. ^ http://groups.google.com/group/nodejs
  7. ^ http://groups.google.com/group/nodejs-dev nodejs-dev
  8. ^ http://www.nodeconf.com/
  9. ^ NodeConf Schedule Announced, By Klint Finley, April 7, 2011, ReadWriteHack
  10. ^ Geitgey, Adam (30 October 2013). "I-Tier: Dismantling the Monoliths". Groupon. Retrieved 30 April 2014.
  11. ^ "SAP AppBuilder". SAP. March 10, 2014. Retrieved March 10, 2014.
  12. ^ "You'll never believe how LinkedIn built its new iPad app". VentureBeat. May 2, 2012. Retrieved May 10, 2012.
  13. ^ [3], LinkedIn's developer blog discusses their Node.js stack optimizations
  14. ^ "Here's why you should be happy that Microsoft is embracing Node.js". The Guardian. November 9, 2011. Retrieved May 10, 2012.
  15. ^ [4], WebMatrix - Front End Web Developers take note (ASP.NET, PHP, node.js and more)
  16. ^ [5], Yahoo! Developer Network announces Cocktails project using Node.js
  17. ^ "Why Walmart is using Node.js". VentureBeat. January 24, 2012. Retrieved May 10, 2012.
  18. ^ "Clash of the Titans: Releasing the Kraken, NodeJS @paypal". fluentconf.com. May 28, 2013. Retrieved September 11, 2013.
  19. ^ Alex Handy (2011-06-24). "Node.js pushes JavaScript to the server-side". SDTimes. Retrieved 2011-09-04.
  20. ^ Harris, Amber (April 1, 2012). "The Birth of Node: Where Did it Come From? Creator Ryan Dahl Shares the History". Devops Angle. Retrieved 26 October 2013.
  21. ^ Synodinos, Dio (December 13, 2010). "Deep inside Node.js with Ryan Dahl". InfoQ. Retrieved 26 October 2013.
  22. ^ McCarthy, Kevin (January 31, 2011). "Node.js Interview: 4 Questions with Creator Ryan Dahl". Streetwise Media. Retrieved 26 October 2013.
  23. ^ Podsechin, Oleg (August 10, 2010). "Ryan Dahl Interview: Part 1". DailyJS. Retrieved 26 October 2013.
  24. ^ [Porting Node to Windows http://blog.nodejs.org/2011/06/23/porting-node-to-windows-with-microsoft%25e2%2580%2599s-help/], Node.js Blog
  25. ^ Dahl, Ryan. "New gatekeeper". Retrieved 26 October 2013.
  26. ^ Finley, Klint (January 30, 2012). "Node.js Creator Ryan Dahl Cedes Role as Gatekeeper to NPM Creator Isaac Schlueter". Silicon Angle. Retrieved 26 October 2013.
  27. ^ Schlueter, Isaac (January 15, 2014). "The Next Phase of Node.js". Retrieved 21 January 2014.
  28. ^ Fontaine, Timothy (January 16, 2014). "Node.js and the Road Ahead". Retrieved 21 January 2014.

Further reading