Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRODUCTION TO By Stepan Vardanyan.

Similar presentations


Presentation on theme: "INTRODUCTION TO By Stepan Vardanyan."— Presentation transcript:

1 INTRODUCTION TO By Stepan Vardanyan

2 CONTENT Theory: Practice: Blocking vs Non blocking i/o.
V8, Libuv, node bindings. node.js history & philosophy. Npm & Frameworks. Comparison. Practice: Project structure, modules. C++ addons for node.js + example. Socket.io + node.js 50 lines realtime chat.

3 Resources CPU RAM HDD Network

4 Problem - Blocking I/O

5 Solution 1 - Multithreading

6 Solution 2 - Non-blocking I/O

7 Reactor design pattern Application 1 Request i/o 5b Execute Handler 5a
4 Event Queue Event Demultiplexer Event Handler Resource Operation Handler 6 Event Loop 3 Event Handler Resource Operation Handler Event Handler 2

8

9 VS

10 VS

11 Node.js Timeline Initial release in 2009.
Express.js 1.0 has been released in 2010. Socket.io initial release in 2010 npm has been released in 2011. iojs separated from node.js in 2014. io.js and node.js had been merged into node.js version 4.0 ( first release version of node.js ) in 2015. Current version is 7.7.x (april 2017) Ryan Dahl - node.js creator

12 Google V8 V8 is google’s open source, high performance, cross browser javascript engine written in C++. V8 compiles and executes javascript source code, handles memory allocation for objects and garbage collects objects it no longer need. Developed in 2008 for Google Chrome, now used in node.js, opera, vivaldi and electron.

13 Libuv - Multiplatform C library
Provides support for asynchronous i/o based on event loops. Full featured event loop backed by unix-epoll & kqueue, windows-IOCP, solaris - event ports. Primarily designed for use in node.js, but it is also used in other software projects.

14 Node.js bindings Reusability Performance
Bindings simply expose core Node.js internal libraries written in C/C++ (c-ares, zlib, OpenSSL, http-parser, etc.) to JavaScript. System programming languages such as C/C++ are generally much faster than other high-level languages.

15 So what node.js exactly is?
“Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.” official documentation Javascript engine - compiles and executes js code Cross platform async i/o layer

16 Node package manager - npm
Developed in 2010 by Isaac Z. Schlueter npm has : packages users registered Npm is largest ecosystem of open source libraries in the world! npm install / update / uninstall “-g” - globally, “-s” - updating in package.json

17 Node.js Philosophy - “The Node way”
Node.js extends UNIX philosophy’s postulats: Small is beautiful. 2. Make each program do one thing well. Node.js postulats: Small core - large userland. Callback comes last - error first.

18 input.txt file: “Hello” Synchronous code Asynchronous code
Callback and Error handling input.txt file: “Hello” Synchronous code Asynchronous code var fs = require("fs"); fs.readFile('input.txt', function (err, data) { if (err) { return console.error(err); } console.log(data.toString()); }); console.log("World"); var fs = require("fs"); var data = fs.readFileSync('input.txt'); console.log(data.toString()); console.log("World"); > Hello > World > World > Hello

19 Node.js frameworks

20 Electron - cross platform framework for desktop applications based on node.js.
Electron is an open source framework for creating native applications with web technologies like JavaScript, HTML, and CSS. It takes care of the hard parts so you can focus on the core of your application.

21 Companies are using node.js

22 Node.js at PayPal In 2013 PayPal rewrited some of services from java to node.js.

23 Node.js at PayPal Development Performance
Built almost twice as fast with fewer people. Written in 33% fewer lines of code. Constructed with 40% fewer files. Performance Double the requests per second vs. the Java application. 35% decrease in the average response time. This resulted in the pages being served 200ms faster — something users will definitely notice.

24 Reasons to move to Node.js
“Any application that can be written in JavaScript, will eventually be written in JavaScript”. Jeff Atwood, co-founder of Stack Overflow "Node allows you to easily build applications with high confidence in build quality. Unit testing is easier. Integration testing is easier. REST is easier. Deployments are easier." Stephen Comissio, senior .NET developer at GoDaddy "We’ve been doing a lot of things twice. Pretty much had to write everything twice - once for the server and once for the client." Kim Trott, director of UI platform engineering at Netflix “The thing that I like best about Node is the amount of power that I've personally found it gives me.” Tom Croucher, Staff site reliability engineer at Uber Technologies

25

26


Download ppt "INTRODUCTION TO By Stepan Vardanyan."

Similar presentations


Ads by Google