Introduction to Node.js Jitendra Kumar Patel Saturday, January

Introduction to Node.js Jitendra Kumar Patel Saturday, January

Introduction to Node.js Jitendra Kumar Patel Saturday, January 31, 2015 Why node.js ?

Node's goal is to provide an easy way to build scalable Network programs About Node.js Created by Ryan Dahl in 2009 Development && maintenance sponsored by Joyent

Licence MIT Last release : 0.10.31 Based on Google V8 Engine +99 000 packages Success Stories.. Other projects like Node.js.

Vert.x => Polygot programming Akka => Scala and Java Tornado => Python Libevent => C EventMachine => Ruby Node.js is not Another Web framework

For beginner Multi-thread Development for the Web. Traditional desktop applications have a user interface wired up with background logic user interfaces are based on Windows Forms, Jswing, WPF, Gtk, Qt, etc. and dependant on operating system

On the web user interfaces are standardized HTML for markup CSS for style JavaScript for dynamic content In the past proprietary technologies existed on the web, e.g. Adobe Flash, ActiveX They are slowly dying

Data is generated on the server, transferred to the client and displayed by the browser Server Side technologies include PHP, JSP, ASP.net, Rails, Djanog, and yes, also node.js REST REST = REpresentational State Transfer Not new technology Architectural style for client-server

Goals of REST.. General interface Scalability of component interface Reduce latency Encapsulate legacy system HTTP Method

GET POST PUT DELETE HTTP Method with CRUD.. POST => Create GET => Read

PUT => Update DELETE => Delete Why node.js ? Non Blocking I/O V8 Javascript Engine Single Thread with Event Loop 40,025 modules

Windows, Linux, Mac 1 Language for Frontend and Backend Active community What is node.js? Asynchronous i/o framework A platform built on Chrome's JavaScript runtime for easily

Core in c++ on top of v8 building fast, scalable Rest of it in javascript network applications. Swiss army knife for network Related http://nodejs.org/ stuffs Can handle thousands of Concurrent connections with

Minimal overhead (cpu/memory) on a single process Its NOT a web framework, and its also NOT a language Why javascript ?!!!

Friendly callbacks Ubiquitous No I/o Primitives One language to RULE them all JavaScript is well known for client-side scripts running inside the browser

node.js is JavaScript running on the server-side SSJS -> Server-Side JavaScript Use a language you know Use the same language for client side and server side JavaScript Engines The idea behind node.js.

Perform asynchronous processing on single thread instead of classical multithread processing, minimize overhead & latency, maximize scalability Scale horizontally instead of vertically Ideal for applications that serve a lot of requests but dont use/need lots of computational power per request Not so ideal for heavy calculations, e.g. massive parallel computing Also: Less problems with concurrency

Node.js Event Loop There are a couple of implications of this apparently very simple and basic model Avoid synchronous code at all costs because it blocks the event loop Which means: callbacks, callbacks, and more callbacks Blocking vs Non-Blocking Example :: Read data from file and show

data Blocking.. Read data from file Show data Do other tasks var data = fs.readFileSync( test.txt ); console.log( data );

console.log( Do other tasks ); Non-Blocking Read data from file When read data completed, show data Do other tasks fs.readFile( test.txt, function( err, data ) {

console.log(data); }); Callback When to use it ? Chat/Messaging Real-time Applications

Intelligent Proxies High Concurrency Applications Communication Hubs Coordinators Node.js for. Web application Websocket server

Ad server Proxy server Streaming server Fast file upload client Any Real-time data apps Anything with high I/O Getting Started..

http://nodejs.org/ and Download tar.gz Extract to any directory $ ./configure && make install File package.json.. Project informations Name Version

Dependencies Licence Main file Etc... Node.js Modules.. https://npmjs.org/ # of modules = 1,21,943

Install module.. $npm install Using module.. var http = require(http); var fs = require(fs); var express = require(express);

In NodeJS

Recently Viewed Presentations

  • EART164: PLANETARY ATMOSPHERES Francis Nimmo F.Nimmo EART164 Spring

    EART164: PLANETARY ATMOSPHERES Francis Nimmo F.Nimmo EART164 Spring

    A.J. 1998 Nebular conditions can be used to predict what components of the solar nebula will be present as gases or solids: Condensation behaviour of most abundant elements of solar nebula e.g. C is stable as CO above 1000K, CH4...
  • Lecture 1: An introduction - Amazon S3

    Lecture 1: An introduction - Amazon S3

    $2,700,000,0001990-2003. TRIG Curriculum: Lecture 1. March 2012. The cost and speed of sequencing has changed dramatically in the last decade. It took 13 years and 2.7 billion dollars for the human genome project to be completed.
  • Keith Vandervelde Marquette County Livestock Specialist Central Wisconsin

    Keith Vandervelde Marquette County Livestock Specialist Central Wisconsin

    Times New Roman Default Design Microsoft Photo Editor 3.0 Photo PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint Presentation PowerPoint ...
  • Présentation PowerPoint

    Présentation PowerPoint

    Réforme des subventions aux énergies fossiles. ODD : MFI PROPOSES. Le potentiel du financement innovant est encore largement inexploité. Les ressources mobilisées grâce à des initiatives de financement innovant du développement représentent en moyenne 2 milliards USD par an.
  • TERPS vs. PANS-Ops - Flight Safety Foundation

    TERPS vs. PANS-Ops - Flight Safety Foundation

    TERPS vs. PANS-Ops. Standard Instrument Departure . If straight out will not work… Climb faster over obstacle. Turn away from obstacle. Keep in sight, "See and avoid"
  • Lec 8: Pipelining - Cornell University

    Lec 8: Pipelining - Cornell University

    Pipelining: Want better Performance. want small CPI (close to 1) with high MIPS and short clock period (high clock frequency) CPU time = instruction count x CPI x clock cycle time. Single Cycle vs Pipelined Processor. See: P&H Chapter 4.5....
  • Chapter 8-Part I - JPSAOS

    Chapter 8-Part I - JPSAOS

    -Up until now, each bonded atom donated one electron each Coordinate Covalent Bonds 6 8 Now O2 has a stable configuration but carbon doesn't So, O2 also donates one of its unshared pairs of electrons 8 8 Coordinate Covalent Bond...
  • LP-Based Algorithms for Capacitated Facility Location

    LP-Based Algorithms for Capacitated Facility Location

    Nondeterministic Turing machines (NDTMs) Same definition as TMs except that. NDTM has . two. transition functions ?0and ?1and a special state called ???????. When NDTM computes a function we envision that at each computational step it makes an arbitrary choice...