This document provides an introduction to Node.js. It discusses why JavaScript can be strange, but explains that JavaScript is relevant as the language of the web. It then discusses what Node.js is and its event-driven, non-blocking architecture. Popular Node.js applications like HTTP servers, REST APIs, and web sockets are mentioned. Examples are provided of building a simple web app with Express and Jade, a REST API with Restify, and using web sockets with Socket.io. The document also discusses using Mongoose with MongoDB for data modeling.
6. JavaScript is strange (II)
function rectangle(x,y) {
this.x = x;
this.y = y;
}
rectangle.prototype.area = function() {
return this.x * this.y;
}
var twoByThree = new rectangle(2,3);
console.log(twoByThree.area());
7. But…JavaScript is relevant
THE language of the WEB
Cross-platform
Huge REACH
JavaScript is everywhere (client, server, libs, frameworks)
Single Page Applications
Server applications
End-to-End JavaScript applications
11. What is Node.js?
Open Source, Cross platform Development platform
Uses V8 JavaScript engine (Google)
“JavaScript on the server”
Node.js is a command line tool
12. Node.js history
Developed in 2009
Published in 2011 (Linux only)
Ryan Dahl, Joyent
From July 2011 Windows version available
Active community: check http://nodeconf.com/
13. Node.js architecture
Node.js is event-driven with Non-blocking I/O
Uses a Event loop for Non-blocking I/O
Node.js is single threaded
15. Node.js applications
“Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network
applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and
efficient, perfect for data-intensive real-time applications that run across distributed devices.”
HTTP server
REST server
Web Sockets
TCP server
Utillities
Building Scalable Network programs