which makes it perfect for building fast, scalable network applications that run across distributed devices.” Built on Chrome's JavaScript engine Event-driven Non-blocking I/O model
is the first web server to support the Java(TM) and JavaScript(TM) programming languages, enabling the creation, delivery and management of live online applications. ” (March 1996)
handed over to a thread (picked from a limited thread pool) for processing. Typically…. Request 1 Request 2 Request n … Thread 2 … (m < n) (for a busy site, m could be a fraction of n) Thread 1 Thread m
the http module to create an http server. var http = require('http'); // Configure the HTTP server. var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello, world"); }); // Listen on port 8000, IP defaults to 127.0.0.1 server.listen(3000); // Log message to the terminal console.log("Server running at http://127.0.0.1:3000/");
Single threaded (avoid concurrency issues) (single threaded out of the box, but still supports multi-threading) Super efficient (can handle 100s of 1000s of connections/minute) Great for real-time applications (because of low latency) And….it’s FREE! (no licensing costs, no expensive dev tools) Vibrant community (15,000+ packages)
any other technology, Node.js is not perfect. Don’t start using it because it’s new and shiny. for example, it’s not the best solution for CPU intensive requests processing We don’t need another bubble.
- mobile games, collaboration tools, chat rooms, etc. APIs exposing JSON based DBs - no need to do any JSON conversion (since it’s JavaScript) Data Streaming - Can process files as they’re still being uploaded (using Streams) Single page apps - AJAX heavy apps can benefit from node’s low response times