SlideShare a Scribd company logo
NODE JS INTRODUCTION
Vatsal Shah
Software Embedded Engineer
Deeps Technology
www.vatsalshah.in
Introduction: Basic
 In simple words Node.js is ‘server-side JavaScript’.
 In not-so-simple words Node.js is a high-performance network
applications framework, well optimized for high concurrent
environments.
 It’s a command line tool.
 In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is
40% JS and 60% C++.
 From the official site:
‘Node's goal is to provide an easy way to build scalable network programs’
- (from nodejs.org!)
11/16/2016
2
Vatsal Shah | Node Js
Why node.js ?
 Non Blocking I/O
 V8 Java script Engine
 Single Thread with Event Loop
 40,025 modules
 Windows, Linux, Mac
 1 Language for Frontend and Backend
 Active community
11/16/2016
3
Vatsal Shah | Node Js
Why node.js ?
Build Fast!
 JS on server and client allows
for more code reuse
 A lite stack (quick create-test
cycle)
 Large number of offerings for
web app creation
11/16/2016
4
Vatsal Shah | Node Js
Why node.js ?
 JS across stack allows easier
refactoring
 Smaller codebase
 See #1 (Build Fast!)
Adapt Fast!
11/16/2016
5
Vatsal Shah | Node Js
Why node.js ?
Run Fast!  Fast V8 Engine
 Great I/O performance with
event loop!
 Small number of layers
11/16/2016
6
Vatsal Shah | Node Js
Why node.js use event-based?
In a normal process cycle the web server while processing the request
will have to wait for the IO operations and thus blocking the next
request to be processed.
Node.JS process each request as events, The server doesn’t wait for
the IO operation to complete while it can handle other request at the
same time.
When the IO operation of first request is completed it will call-back
the server to complete the request.
11/16/2016
7
Vatsal Shah | Node Js
HTTP Method
 GET
 POST
 PUT
 DELETE
 GET => Read
 POST => Create
 PUT => Update
 DELETE => Delete
11/16/2016
8
Vatsal Shah | Node Js
Node.js Event Loop
11/16/2016
9
Vatsal Shah | Node Js
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
11/16/2016
10
Vatsal Shah | Node Js
Blocking
Read data from file
Show data
Do other tasks
var data = fs.readFileSync( “test.txt” );
console.log( data );
console.log( “Do other tasks” );
11/16/2016
11
Vatsal Shah | Node Js
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);
});
11/16/2016
12
Vatsal Shah | Node Js
Node.js Modules
 https://npmjs.org/
 # of modules = 1,21,943
11/16/2016
13
Vatsal Shah | Node Js
Modules
 $npm install <module name>
 Modules allow Node to be extended (act as libaries)
 We can include a module with the global require function, require(‘module’)
 Node provides core modules that can be included by their name:
 File System – require(‘fs’)
 Http – require(‘http’)
 Utilities – require(‘util’)
11/16/2016
14
Vatsal Shah | Node Js
Modules
 We can also break our application up into modules and require
them using a file path:
 ‘/’ (absolute path), ‘./’ and ‘../’ (relative to calling file)
 Any valid type can be exported from a module by assigning it to
module.exports
11/16/2016
15
Vatsal Shah | Node Js
NPM Versions
 Var Versions (version [Major].[Minor].[Patch]):
 = (default), >, <, >=, <=
 * most recent version
 1.2.3 – 2.3.4 version greater than 1.2.3 and less than 2.3.4
 ~1.2.3 most recent patch version greater than or equal to 1.2.3 (>=1.2.3 <1.3.0)
 ^1.2.3 most recent minor version greater than or equal to 1.2.3 (>=1.2.3 <2.0.0)
11/16/2016
16
Vatsal Shah | Node Js
NPM Commands
 Common npm commands:
 npm init initialize a package.json file
 npm install <package name> -g install a package, if –g option is given package
will be installed as a global, --save and --save-dev will add package to your dependencies
 npm install install packages listed in package.json
 npm ls –g listed local packages (without –g) or global packages (with –g)
 npm update <package name> update a package
11/16/2016
17
Vatsal Shah | Node Js
File package.json
 First, we need to create a package.json file for our app
 Contains metadata for our app and lists the dependencies
 Package.json Interactive Guide
Project informations
 Name
 Version
 Dépendances
 Licence
 Main file
Etc...
11/16/2016
18
Vatsal Shah | Node Js
Example-1: Getting Started & Hello World
 Install/build Node.js.
 (Yes! Windows installer is available!)
 Open your favorite editor and start typing JavaScript.
 When you are done, open cmd/terminal and type this:
node YOUR_FILE.js
 Here is a simple example, which prints ‘hello world’
var sys = require sys ;
setTimeout(function(){
sys.puts world ;},3000 ;
sys.puts hello ;
//it prints hello first and waits for 3 seconds and then prints world
11/16/2016
19
Vatsal Shah | Node Js
Node.js Ecosystem
 Node.js heavily relies on modules, in previous examples require keyword
loaded the http & net modules.
 Creating a module is easy, just put your JavaScript code in a separate js
file and include it in your code by using keyword require, like:
var modulex = require ./modulex ;
 Libraries in Node.js are called packages and they can be installed by
typing
npm install package_name ; //package should be available in npm registry @
nmpjs.org
 NPM (Node Package Manager) comes bundled with Node.js installation.
11/16/2016
20
Vatsal Shah | Node Js
Example -2 &3 (HTTP Server & TCP Server)
 Following code creates an HTTP Server and prints ‘Hello World’ on the browser:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");
 Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it:
var net = require('net');
net.createServer(function (socket) {
socket.write("Echo serverrn");
socket.pipe(socket); }).listen(6000, "127.0.0.1");
11/16/2016
21
Vatsal Shah | Node Js
Example-4: Lets connect to a DB (MongoDB)
 Install mongojs using npm, a mongoDB driver for Node.js
npm install mongojs
 Code to retrieve all the documents from a collection:
var db = require("mongojs")
.connect("localhost:27017/test", ['test']);
db.test.find({}, function(err, posts) {
if( err || !posts) console.log("No posts found");
else posts.forEach( function(post) {
console.log(post);
});
});
11/16/2016
22
Vatsal Shah | Node Js
When to use it ?
 Chat/Messaging
 Real-time Applications
 High Concurrency Applications
 Coordinators
 Web application
 Streaming server
 Fast file upload client
 Any Real-time data apps
 Anything with high I/O
11/16/2016
23
Vatsal Shah | Node Js
Who is using Node.js in production?
11/16/2016
24
Vatsal Shah | Node Js
Getting Started
 http://nodejs.org/ and Download tar.gz
 Extract to any directory
 $ ./configure && make install
11/16/2016
25
Vatsal Shah | Node Js
Thank You 

More Related Content

PPT
Node.js Basics
PPTX
Introduction to Node.js
PPTX
Introduction to node.js
PPTX
Basic Concept of Node.js & NPM
PPTX
Node js Introduction
PDF
An Introduction of Node Package Manager (NPM)
PDF
Node JS Crash Course
PDF
Introduction to Node.js
Node.js Basics
Introduction to Node.js
Introduction to node.js
Basic Concept of Node.js & NPM
Node js Introduction
An Introduction of Node Package Manager (NPM)
Node JS Crash Course
Introduction to Node.js

What's hot (20)

PDF
NodeJS for Beginner
PPTX
Express js
PPTX
Introduction to NodeJS
PPTX
Node js introduction
PPTX
Introduction to Node.js
PDF
Nodejs presentation
PPTX
Introduction to Node js
PPTX
NodeJS - Server Side JS
PPTX
Introduction Node.js
PPTX
Node.js Express
PPTX
Build RESTful API Using Express JS
PDF
Nodejs Explained with Examples
PDF
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
PDF
jQuery for beginners
PPTX
JSON: The Basics
PPTX
Introduction to MERN
PDF
Spring Framework - AOP
PPTX
Reactjs
PPTX
NodeJS for Beginner
Express js
Introduction to NodeJS
Node js introduction
Introduction to Node.js
Nodejs presentation
Introduction to Node js
NodeJS - Server Side JS
Introduction Node.js
Node.js Express
Build RESTful API Using Express JS
Nodejs Explained with Examples
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
jQuery for beginners
JSON: The Basics
Introduction to MERN
Spring Framework - AOP
Reactjs
Ad

Viewers also liked (20)

PDF
Poster IOTROBOT vatsalnshah_ec_indusuniversity
PPTX
Presentation IOT Robot
PPTX
Introduction to node.js
PPTX
From Hello World to Real World - Container Days Boston 2016
PDF
Project ideas ece students
PPTX
introduction to node.js
DOCX
iot report 3 (2)
PDF
project report on IoT
KEY
Node.js ― Hello, world! の1歩先へ。
PPTX
Node js meetup
PDF
Report IOT Robot
PDF
Introduction to node js - From "hello world" to deploying on azure
PDF
EmpireJS: Hacking Art with Node js and Image Analysis
PPTX
Node js for beginners
PDF
Report Automatic led emergency light
PPTX
Am fm transmitter
PPTX
Search and rescue
DOCX
pick-and-place-robot
PPTX
Internet of Things
Poster IOTROBOT vatsalnshah_ec_indusuniversity
Presentation IOT Robot
Introduction to node.js
From Hello World to Real World - Container Days Boston 2016
Project ideas ece students
introduction to node.js
iot report 3 (2)
project report on IoT
Node.js ― Hello, world! の1歩先へ。
Node js meetup
Report IOT Robot
Introduction to node js - From "hello world" to deploying on azure
EmpireJS: Hacking Art with Node js and Image Analysis
Node js for beginners
Report Automatic led emergency light
Am fm transmitter
Search and rescue
pick-and-place-robot
Internet of Things
Ad

Similar to Nodejs vatsal shah (20)

PPTX
Intro to Node.js (v1)
PDF
🚀 Node.js Simplified – A Visual Guide for Beginners!
PPTX
Introduction to node.js By Ahmed Assaf
DOCX
unit 2 of Full stack web development subject
PPTX
PPTX
Introduction to node.js GDD
ODP
Introduce about Nodejs - duyetdev.com
PPTX
Nodejs
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
PPTX
Node.js Chapter1
PPTX
A complete guide to Node.js
PPTX
Beginners Node.js
PPTX
Node js Powerpoint Presentation by PDEU Gandhinagar
PPTX
PDF
Node intro
PPTX
Kalp Corporate Node JS Perfect Guide
PDF
Node.js essentials
PDF
Tech io nodejs_20130531_v0.6
PDF
Node.js for beginner
PPT
Node js beginner
Intro to Node.js (v1)
🚀 Node.js Simplified – A Visual Guide for Beginners!
Introduction to node.js By Ahmed Assaf
unit 2 of Full stack web development subject
Introduction to node.js GDD
Introduce about Nodejs - duyetdev.com
Nodejs
Server Side Web Development Unit 1 of Nodejs.pptx
Node.js Chapter1
A complete guide to Node.js
Beginners Node.js
Node js Powerpoint Presentation by PDEU Gandhinagar
Node intro
Kalp Corporate Node JS Perfect Guide
Node.js essentials
Tech io nodejs_20130531_v0.6
Node.js for beginner
Node js beginner

More from Vatsal N Shah (20)

PDF
Machine Learning Project - Default credit card clients
PDF
I am sharing my journey with Indus University and Indus Family. Read Page No:...
PDF
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
DOCX
Projects
PPTX
Raspbeery Pi : An Introduction
PDF
Report Remote communication of Robotic module using lifa
PDF
Floor cleaning robot report vatsal shah_ec_7th sem
PDF
IRC Magazine Issue_1
PDF
Advanced wheel chair vatsal shah
PDF
Configuring lifa for remote communication using web architecture
PDF
Control robotic module using LIFA
PPTX
Trapatt diode
PPTX
Telemedicine
PDF
E-sync-Revista-Editon-1
PDF
GSM based lcd dsiplay
DOCX
Project report format
PDF
Abstract - Interfacing 5 x7 matrix led display to 8051
PDF
5x7 matrix led display
PDF
A seminar report on flex sensor
PPTX
Flex sensor
Machine Learning Project - Default credit card clients
I am sharing my journey with Indus University and Indus Family. Read Page No:...
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
Projects
Raspbeery Pi : An Introduction
Report Remote communication of Robotic module using lifa
Floor cleaning robot report vatsal shah_ec_7th sem
IRC Magazine Issue_1
Advanced wheel chair vatsal shah
Configuring lifa for remote communication using web architecture
Control robotic module using LIFA
Trapatt diode
Telemedicine
E-sync-Revista-Editon-1
GSM based lcd dsiplay
Project report format
Abstract - Interfacing 5 x7 matrix led display to 8051
5x7 matrix led display
A seminar report on flex sensor
Flex sensor

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectral efficient network and resource selection model in 5G networks
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Modernizing your data center with Dell and AMD
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity

Nodejs vatsal shah

  • 1. NODE JS INTRODUCTION Vatsal Shah Software Embedded Engineer Deeps Technology www.vatsalshah.in
  • 2. Introduction: Basic  In simple words Node.js is ‘server-side JavaScript’.  In not-so-simple words Node.js is a high-performance network applications framework, well optimized for high concurrent environments.  It’s a command line tool.  In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++.  From the official site: ‘Node's goal is to provide an easy way to build scalable network programs’ - (from nodejs.org!) 11/16/2016 2 Vatsal Shah | Node Js
  • 3. Why node.js ?  Non Blocking I/O  V8 Java script Engine  Single Thread with Event Loop  40,025 modules  Windows, Linux, Mac  1 Language for Frontend and Backend  Active community 11/16/2016 3 Vatsal Shah | Node Js
  • 4. Why node.js ? Build Fast!  JS on server and client allows for more code reuse  A lite stack (quick create-test cycle)  Large number of offerings for web app creation 11/16/2016 4 Vatsal Shah | Node Js
  • 5. Why node.js ?  JS across stack allows easier refactoring  Smaller codebase  See #1 (Build Fast!) Adapt Fast! 11/16/2016 5 Vatsal Shah | Node Js
  • 6. Why node.js ? Run Fast!  Fast V8 Engine  Great I/O performance with event loop!  Small number of layers 11/16/2016 6 Vatsal Shah | Node Js
  • 7. Why node.js use event-based? In a normal process cycle the web server while processing the request will have to wait for the IO operations and thus blocking the next request to be processed. Node.JS process each request as events, The server doesn’t wait for the IO operation to complete while it can handle other request at the same time. When the IO operation of first request is completed it will call-back the server to complete the request. 11/16/2016 7 Vatsal Shah | Node Js
  • 8. HTTP Method  GET  POST  PUT  DELETE  GET => Read  POST => Create  PUT => Update  DELETE => Delete 11/16/2016 8 Vatsal Shah | Node Js
  • 9. Node.js Event Loop 11/16/2016 9 Vatsal Shah | Node Js 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
  • 10. Blocking vs. Non-Blocking Example :: Read data from file and show data 11/16/2016 10 Vatsal Shah | Node Js
  • 11. Blocking Read data from file Show data Do other tasks var data = fs.readFileSync( “test.txt” ); console.log( data ); console.log( “Do other tasks” ); 11/16/2016 11 Vatsal Shah | Node Js
  • 12. 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); }); 11/16/2016 12 Vatsal Shah | Node Js
  • 13. Node.js Modules  https://npmjs.org/  # of modules = 1,21,943 11/16/2016 13 Vatsal Shah | Node Js
  • 14. Modules  $npm install <module name>  Modules allow Node to be extended (act as libaries)  We can include a module with the global require function, require(‘module’)  Node provides core modules that can be included by their name:  File System – require(‘fs’)  Http – require(‘http’)  Utilities – require(‘util’) 11/16/2016 14 Vatsal Shah | Node Js
  • 15. Modules  We can also break our application up into modules and require them using a file path:  ‘/’ (absolute path), ‘./’ and ‘../’ (relative to calling file)  Any valid type can be exported from a module by assigning it to module.exports 11/16/2016 15 Vatsal Shah | Node Js
  • 16. NPM Versions  Var Versions (version [Major].[Minor].[Patch]):  = (default), >, <, >=, <=  * most recent version  1.2.3 – 2.3.4 version greater than 1.2.3 and less than 2.3.4  ~1.2.3 most recent patch version greater than or equal to 1.2.3 (>=1.2.3 <1.3.0)  ^1.2.3 most recent minor version greater than or equal to 1.2.3 (>=1.2.3 <2.0.0) 11/16/2016 16 Vatsal Shah | Node Js
  • 17. NPM Commands  Common npm commands:  npm init initialize a package.json file  npm install <package name> -g install a package, if –g option is given package will be installed as a global, --save and --save-dev will add package to your dependencies  npm install install packages listed in package.json  npm ls –g listed local packages (without –g) or global packages (with –g)  npm update <package name> update a package 11/16/2016 17 Vatsal Shah | Node Js
  • 18. File package.json  First, we need to create a package.json file for our app  Contains metadata for our app and lists the dependencies  Package.json Interactive Guide Project informations  Name  Version  Dépendances  Licence  Main file Etc... 11/16/2016 18 Vatsal Shah | Node Js
  • 19. Example-1: Getting Started & Hello World  Install/build Node.js.  (Yes! Windows installer is available!)  Open your favorite editor and start typing JavaScript.  When you are done, open cmd/terminal and type this: node YOUR_FILE.js  Here is a simple example, which prints ‘hello world’ var sys = require sys ; setTimeout(function(){ sys.puts world ;},3000 ; sys.puts hello ; //it prints hello first and waits for 3 seconds and then prints world 11/16/2016 19 Vatsal Shah | Node Js
  • 20. Node.js Ecosystem  Node.js heavily relies on modules, in previous examples require keyword loaded the http & net modules.  Creating a module is easy, just put your JavaScript code in a separate js file and include it in your code by using keyword require, like: var modulex = require ./modulex ;  Libraries in Node.js are called packages and they can be installed by typing npm install package_name ; //package should be available in npm registry @ nmpjs.org  NPM (Node Package Manager) comes bundled with Node.js installation. 11/16/2016 20 Vatsal Shah | Node Js
  • 21. Example -2 &3 (HTTP Server & TCP Server)  Following code creates an HTTP Server and prints ‘Hello World’ on the browser: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");  Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it: var net = require('net'); net.createServer(function (socket) { socket.write("Echo serverrn"); socket.pipe(socket); }).listen(6000, "127.0.0.1"); 11/16/2016 21 Vatsal Shah | Node Js
  • 22. Example-4: Lets connect to a DB (MongoDB)  Install mongojs using npm, a mongoDB driver for Node.js npm install mongojs  Code to retrieve all the documents from a collection: var db = require("mongojs") .connect("localhost:27017/test", ['test']); db.test.find({}, function(err, posts) { if( err || !posts) console.log("No posts found"); else posts.forEach( function(post) { console.log(post); }); }); 11/16/2016 22 Vatsal Shah | Node Js
  • 23. When to use it ?  Chat/Messaging  Real-time Applications  High Concurrency Applications  Coordinators  Web application  Streaming server  Fast file upload client  Any Real-time data apps  Anything with high I/O 11/16/2016 23 Vatsal Shah | Node Js
  • 24. Who is using Node.js in production? 11/16/2016 24 Vatsal Shah | Node Js
  • 25. Getting Started  http://nodejs.org/ and Download tar.gz  Extract to any directory  $ ./configure && make install 11/16/2016 25 Vatsal Shah | Node Js