Ceren Altunal Podlech http://slides.com/cerenaltunal/deck-3#/
A little bit of story...
Its development and maintenance was spearheaded by Ryan Dahl. 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 desired an easier way.
He was aiming to create real-time websites with push capability, “inspired by applications like Gmail”.
after over 20 years of stateless-web based on the stateless request-response paradigm, we finally have web applications with real-time, two-way connections, where both the client and server can initiate communication, allowing them to exchange data freely.
What is Node.js?
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.
Node.js
Allows you to build scalable network application using Javascript on the server side. In the case of most pre-node Javascript, it existed in the browser and took user events manipulate the content of the rendered page in the browser. Manipulating these events were the only real interaction the code had. It was a single route of actions that the programmer had to deal with. The Javascript world on the browser side was relatively simple...
All of a sudden JavaScript now can deal with all of the interactions on a server.
So how does JavaScript, and Node, deal with this new complexity on the server side?
?
Event loop
The event loop is key to understanding this entire flow. Node provides the event loop as a language construct, not just as a library. In most other event loops there is a call to start things. With the Node event loop it starts and doesn’t end until the last callback to perform.
By the event loop and the very nature of JavaScript and Node, there are a lot of callbacks dealing with I/O that deal with and initiate callbacks from other I/O.
Threading
Operates on a single thread
thousands of concurrent connections, without worrying about the cost of context-switching between threads
Any function performing I/O must use a callback.
A downside of this approach is that Node.js doesn't allow scaling with the number of CPU cores of the machine it is running on.

Blocking Code
Blocking Code

Non-Blocking Code
Non-Blocking Code
Loading two files
fs.readFile('/etc/hosts, function(err, contents)'{
console.log('Doing something else')
});var contents= fs.readFileSync('/etc/hosts');
console.log('Doing sth else')Read file fromFilesystem, set equal to "contents"
Print contents
Do something elseRead file from Filesystem
whenever you're complete, print the contents
Do Something elseV8
V8 is the JavaScript execution engine built for Google Chrome, open-sourced by Google in 2008. Written in C++, V8 compiles JavaScript source code just-in-time to machine code instead of interpreting it in real time.
Node.js contains libuv to handle asynchronous events. V8 provides the run-time for JavaScript. Libuv is an abstraction layer for 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 resides in a JavaScript library. The Node.js bindings, written in C++, connect these technologies to each other and to the operating system.
Unified API
Node.js combined with a browser, a document DB (such as MongoDB or CouchDB) and JSON offers a unified JavaScript development stack.
With the increased attention to client-side frameworks and the adaptation of what were essentially server-side development patterns like MVC, MVP, MVVM, etc., Node.js allows the reuse of the same model and service interface between client-side and server-side.
NPM
Npm is the pre-installed package manager for the Node.js server platform.
It is used to install Node.js programs and libraries from the npm registry.
By organizing the installation and management of third-party Node.js programs, it helps developers build faster.
npm is not to be confused with the commonJS require() statement. It is not used to load code: instead, it is used to install code and manage code dependencies from the command line. The packages found in the npm registry can range from simple helper libraries like underscore.js to task runners like Grunt.
Webserver
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');What you can build with node.js?
Websocket Server (Like a chat server) Fast file Upload Client Ad Server Any Real Time Data Apps

It is not a framework.
Unified programming language (JavaScript) allows for consistent use of language at frontend and backend Event-driven → facilitates user interaction Event loop instead of processes or threads. it does not need to be called explicitly. Asynchronous (non-blocking) I/O model & single threaded event loop → functions returned immediately & allows other I/O procedures to run in Fashionable language, swiftly gaining in popularity, expanding libraries
To Sum Up;
http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js
http://en.wikipedia.org/wiki/Node.js
http://socket.io/get-started/chat/
REFERENCES
Code Academy Learn Node.js
Questions
?
Thanks for your attention
deck
By ceren altunal
deck
- 433