SlideShare a Scribd company logo
5
Most read
9
Most read
15
Most read
Basic Concept of Node.Js &
NPM
Bhargav Anadkat
Twitter @bhargavlalo
Facebook bhargav.anadkat
WHAT TO EXPECT AHEAD….
 Introduction Video Song
 What is NodeJS?
 Reasons to use NodeJS
 Confusing With NodeJS
 Who uses NodeJS?
 NodeJs Event Loop
 Introduction to NPM (Node Package
Manager)
 Some good modules
 List of NodeJS Core Packages
 NodeJS Installation
 Command Line Intro & Node
Command
 First Hello World Example
 Node.js Ecosystem
 Blocking I/O and Non Blocking
I/O
 Non Blocking Example
 Create Package Dependency
 Example TCP Server
 Example MongoDB
 Example Twitter Streaming
 Advance Example
 Question/Answer
 Thank You
WHAT IS NODEJS?
 NodeJS is an open source, cross platform runtime
environment for server side and networking
application.
 Basically, NodeJS is server side programming
language like PHP, C#, Python etc.
 In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written
JavaScript. It is 40% JS and 60% C++.
 NodeJS is cross platform. So it runs well on Linux
systems, Mac, can also run on Windows systems.
 It provided an event driven architecture and a non
blocking I/O that optimize and scalability. These
technology uses for real time application
#2 WHAT IS NODEJS?
 It used Google JavaScript V8 Engine to Execute
Code.
 V8 is an open source JavaScript engine developed
by Google. Its written in C++ and is used in Google
Chrome Browser.
 NodeJS invented in 2009 by Ryan Dahl.
 NodeJS is popular in development because front &
backend side both uses JavaScript Code.
‘Node's goal is to provide an easy way to build
scalable network programs’ - (from nodejs.org!)
REASONS TO USE NODEJS
 It is Open Source and cross platform. It runs well on
Linux systems, Mac, can also run on Windows
systems.
 It is fast.
 Node.js wins with Ubiquity
 Node.js wins with Data Streaming
 Node.js wins with Database Queries
 Real Time web applications Support
 Node.js –Effective Tooling with NPM
 Many more…
CONFUSING WITH NODEJS
 Programs for Node.js are written in JavaScript but not
in the same JavaScript we are use to. There is no DOM
implementation provided by Node.js, i.e. you can not
do this:
var element = document.getElementById(“elementId”);
 Everything inside Node.js runs in a single-thread.
WHO USES NODEJS?
WHO IS USING NODE.JS IN PRODUCTION?
 Yahoo! : iPad App Livestand uses Yahoo!
Manhattan framework which is based on Node.js.
 LinkedIn : LinkedIn uses a combination of Node.js
and MongoDB for its mobile platform. iOS and
Android apps are based on it.
 eBay : Uses Node.js along with ql.io to help
application developers in improving eBay’s end
user experience.
 Dow Jones : The WSJ Social front-end is written
completely in Node.js, using Express.js, and many
other modules.
 Complete list can be found at:
https://github.com/joyent/node/wiki/Projects,-
Applications,-and-Companies-Using-Node
NODEJS EVENT LOOP
 Event-loops are the core of event-driven programming,
almost all the UI programs use event-loops to track the
user event, for example: Clicks, Ajax Requests etc.
Client
Event loop
(main thread)
C++
Threadpool
(worker
threads)
Clients send HTTP requests
to Node.js server
An Event-loop is woken up by OS,
passes request and response objects
to the thread-pool
Long-running jobs run
on worker threads
Response is sent
back to main thread
via callback
Event loop returns
result to client
INTRODUCTION TO NPM (NODE PACKAGE
MANAGER)
 npm is the package manager for Node.js and JavaScript
 We can create public & private module
 Find all modules on NPM website : https://www.npmjs.com/
 There 5.5 Lacks+ packages available So in world its largest JavaScript
package manager.
 Below are some most popular packages which used in many projects.
 lodash
 express
 request
 react
 debug
 bluebird
 async
 chalk
 commander
SOME GOOD MODULES
 Express – to make things simpler e.g. syntax, DB
connections.
 Jade – HTML template system
 Socket.IO – to create real-time apps
 Nodemon – to monitor Node.js and push change
automatically
 CoffeeScript – for easier JavaScript development
LIST OF NODEJS CORE PACKAGES
 Assertion
 Testing
 File System
 Path
 Debugger
 Query Strings
 Events
 String
 TLS/SSL
 URL
 Buffer
 HTTP/HTTPS
 C/C++ Addons
 Crypto
 Punycode
 Domain
 Stream
 Decoder
 TTY
 Utilities
 Child Processes
 OS
 Cluster
 Process
 DNS
 REPL
 Core
 Timers
 UDP/Datagram
 VM
NODEJS INSTALLATION
 Download at https://nodejs.org/en/download/
 Available in installable file and source code.
 It is easy to install so you can start start developing
today on any platform.
 In latest version npm (Node Package Manager)
already available inside it so no need to download
npm separately.
COMMAND LINE INTRO & NODE COMMAND
 Windows platform, Open command prompt (cmd)
 Below are some node basic command introduction
 node : open node editor and write and execute
node JavaScript code there.
 node -v : check the node version
 node -h : help command
 node [packagename]: it runs your package
(module)
FIRST HELLO WORLD EXAMPLE
 Hello world example code you can found on below
github link:
https://github.com/bhargavlalo/ba-nodejs-
example/blob/master/1-helloworld/1-helloworld.js
NODE.JS ECOSYSTEM
 Node.js heavily relies on modules, in previous
examples require keyword loaded the http
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.
BLOCKING I/O AND NON BLOCKING I/O
 Traditional I/O
var result = db.query(“select x from table_Y”);
doSomethingWith(result); //wait for result!
doSomethingWithOutResult(); //execution is blocked!
 Non-traditional, Non-blocking I/O
db.query(“select x from table_Y”,function (result){
doSomethingWith(result); //wait for result!
});
doSomethingWithOutResult(); //executes without any
delay!
NON-BLOCKING EXAMPLE
 Nonblocking example code:
https://github.com/bhargavlalo/ba-nodejs-
example/blob/master/4-nonblocking/nonblocking.js
EXAMPLE TCP SERVER
 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");
EXAMPLE 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);
});
});
EXAMPLE TWITTER STREAMING
 Install nTwitter module using npm:
Npm install ntwitter
 Code:
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: ‘c_key’,
consumer_secret: ‘c_secret’,
access_token_key: ‘token_key’,
access_token_secret: ‘token_secret’});
twit.stream('statuses/sample', function(stream) {
stream.on('data', function (data) {
console.log(data); });
});
ADVANCE EXAMPLES
 Some advance examples created on my github
repo.
 Below is the link
https://github.com/bhargavlalo/ba-nodejs-example
 Examples
 Desktop Application
 HTML Render
 Node Mailer
Question & Answer
Thank You
console.log(“Bhargav Anadkat”);

More Related Content

What's hot (20)

PPTX
Introduction to Node js
Akshay Mathur
 
PPTX
NodeJS - Server Side JS
Ganesh Kondal
 
PDF
Nodejs presentation
Arvind Devaraj
 
PPTX
NodeJS guide for beginners
Enoch Joshua
 
PPTX
Express js
Manav Prasad
 
PPT
Node.js Basics
TheCreativedev Blog
 
PPTX
Introduction to NodeJS
Cere Labs Pvt. Ltd
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
What Is Express JS?
Simplilearn
 
PPTX
ReactJS presentation.pptx
DivyanshGupta922023
 
PPT
Vue.js Getting Started
Murat Doğan
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PPTX
React state
Ducat
 
PPTX
Express JS
Alok Guha
 
PPTX
Nodejs functions & modules
monikadeshmane
 
PPTX
Introduction to React JS
Arnold Asllani
 
PDF
Express node js
Yashprit Singh
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
Introduction to Node js
Akshay Mathur
 
NodeJS - Server Side JS
Ganesh Kondal
 
Nodejs presentation
Arvind Devaraj
 
NodeJS guide for beginners
Enoch Joshua
 
Express js
Manav Prasad
 
Node.js Basics
TheCreativedev Blog
 
Introduction to NodeJS
Cere Labs Pvt. Ltd
 
[Final] ReactJS presentation
洪 鹏发
 
What Is Express JS?
Simplilearn
 
ReactJS presentation.pptx
DivyanshGupta922023
 
Vue.js Getting Started
Murat Doğan
 
Introduction Node.js
Erik van Appeldoorn
 
React state
Ducat
 
Express JS
Alok Guha
 
Nodejs functions & modules
monikadeshmane
 
Introduction to React JS
Arnold Asllani
 
Express node js
Yashprit Singh
 
Introduction to spring boot
Santosh Kumar Kar
 

Similar to Basic Concept of Node.js & NPM (20)

PPTX
NodeJS Presentation
Faisal Shahzad Khan
 
PDF
🚀 Node.js Simplified – A Visual Guide for Beginners!
Tpoint Tech Blog
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
PPTX
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
 
DOCX
unit 2 of Full stack web development subject
JeneferAlan1
 
PDF
Node.js for beginner
Sarunyhot Suwannachoti
 
PPTX
Kalp Corporate Node JS Perfect Guide
Kalp Corporate
 
PPTX
Node js for beginners
Arjun Sreekumar
 
ODP
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
 
ODP
Node js presentation
shereefsakr
 
PPTX
Nodejs
dssprakash
 
PDF
Node js (runtime environment + js library) platform
Sreenivas Kappala
 
PPTX
Nodejs
Vinod Kumar Marupu
 
PDF
Node js
Rohan Chandane
 
PPTX
Proposal
Constantine Priemski
 
PDF
Node, express & sails
Brian Shannon
 
PDF
Server Side Apocalypse, JS
Md. Sohel Rana
 
PDF
Node.js.pdf
gulfam ali
 
PPTX
Introduction to Node.js
Vikash Singh
 
PPTX
An overview of node.js
valuebound
 
NodeJS Presentation
Faisal Shahzad Khan
 
🚀 Node.js Simplified – A Visual Guide for Beginners!
Tpoint Tech Blog
 
Intro to Node.js (v1)
Chris Cowan
 
Introduction to node.js By Ahmed Assaf
Ahmed Assaf
 
unit 2 of Full stack web development subject
JeneferAlan1
 
Node.js for beginner
Sarunyhot Suwannachoti
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate
 
Node js for beginners
Arjun Sreekumar
 
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
 
Node js presentation
shereefsakr
 
Nodejs
dssprakash
 
Node js (runtime environment + js library) platform
Sreenivas Kappala
 
Node, express & sails
Brian Shannon
 
Server Side Apocalypse, JS
Md. Sohel Rana
 
Node.js.pdf
gulfam ali
 
Introduction to Node.js
Vikash Singh
 
An overview of node.js
valuebound
 
Ad

Recently uploaded (20)

PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Ad

Basic Concept of Node.js & NPM

  • 1. Basic Concept of Node.Js & NPM Bhargav Anadkat Twitter @bhargavlalo Facebook bhargav.anadkat
  • 2. WHAT TO EXPECT AHEAD….  Introduction Video Song  What is NodeJS?  Reasons to use NodeJS  Confusing With NodeJS  Who uses NodeJS?  NodeJs Event Loop  Introduction to NPM (Node Package Manager)  Some good modules  List of NodeJS Core Packages  NodeJS Installation  Command Line Intro & Node Command  First Hello World Example  Node.js Ecosystem  Blocking I/O and Non Blocking I/O  Non Blocking Example  Create Package Dependency  Example TCP Server  Example MongoDB  Example Twitter Streaming  Advance Example  Question/Answer  Thank You
  • 3. WHAT IS NODEJS?  NodeJS is an open source, cross platform runtime environment for server side and networking application.  Basically, NodeJS is server side programming language like PHP, C#, Python etc.  In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++.  NodeJS is cross platform. So it runs well on Linux systems, Mac, can also run on Windows systems.  It provided an event driven architecture and a non blocking I/O that optimize and scalability. These technology uses for real time application
  • 4. #2 WHAT IS NODEJS?  It used Google JavaScript V8 Engine to Execute Code.  V8 is an open source JavaScript engine developed by Google. Its written in C++ and is used in Google Chrome Browser.  NodeJS invented in 2009 by Ryan Dahl.  NodeJS is popular in development because front & backend side both uses JavaScript Code. ‘Node's goal is to provide an easy way to build scalable network programs’ - (from nodejs.org!)
  • 5. REASONS TO USE NODEJS  It is Open Source and cross platform. It runs well on Linux systems, Mac, can also run on Windows systems.  It is fast.  Node.js wins with Ubiquity  Node.js wins with Data Streaming  Node.js wins with Database Queries  Real Time web applications Support  Node.js –Effective Tooling with NPM  Many more…
  • 6. CONFUSING WITH NODEJS  Programs for Node.js are written in JavaScript but not in the same JavaScript we are use to. There is no DOM implementation provided by Node.js, i.e. you can not do this: var element = document.getElementById(“elementId”);  Everything inside Node.js runs in a single-thread.
  • 8. WHO IS USING NODE.JS IN PRODUCTION?  Yahoo! : iPad App Livestand uses Yahoo! Manhattan framework which is based on Node.js.  LinkedIn : LinkedIn uses a combination of Node.js and MongoDB for its mobile platform. iOS and Android apps are based on it.  eBay : Uses Node.js along with ql.io to help application developers in improving eBay’s end user experience.  Dow Jones : The WSJ Social front-end is written completely in Node.js, using Express.js, and many other modules.  Complete list can be found at: https://github.com/joyent/node/wiki/Projects,- Applications,-and-Companies-Using-Node
  • 9. NODEJS EVENT LOOP  Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Event loop (main thread) C++ Threadpool (worker threads) Clients send HTTP requests to Node.js server An Event-loop is woken up by OS, passes request and response objects to the thread-pool Long-running jobs run on worker threads Response is sent back to main thread via callback Event loop returns result to client
  • 10. INTRODUCTION TO NPM (NODE PACKAGE MANAGER)  npm is the package manager for Node.js and JavaScript  We can create public & private module  Find all modules on NPM website : https://www.npmjs.com/  There 5.5 Lacks+ packages available So in world its largest JavaScript package manager.  Below are some most popular packages which used in many projects.  lodash  express  request  react  debug  bluebird  async  chalk  commander
  • 11. SOME GOOD MODULES  Express – to make things simpler e.g. syntax, DB connections.  Jade – HTML template system  Socket.IO – to create real-time apps  Nodemon – to monitor Node.js and push change automatically  CoffeeScript – for easier JavaScript development
  • 12. LIST OF NODEJS CORE PACKAGES  Assertion  Testing  File System  Path  Debugger  Query Strings  Events  String  TLS/SSL  URL  Buffer  HTTP/HTTPS  C/C++ Addons  Crypto  Punycode  Domain  Stream  Decoder  TTY  Utilities  Child Processes  OS  Cluster  Process  DNS  REPL  Core  Timers  UDP/Datagram  VM
  • 13. NODEJS INSTALLATION  Download at https://nodejs.org/en/download/  Available in installable file and source code.  It is easy to install so you can start start developing today on any platform.  In latest version npm (Node Package Manager) already available inside it so no need to download npm separately.
  • 14. COMMAND LINE INTRO & NODE COMMAND  Windows platform, Open command prompt (cmd)  Below are some node basic command introduction  node : open node editor and write and execute node JavaScript code there.  node -v : check the node version  node -h : help command  node [packagename]: it runs your package (module)
  • 15. FIRST HELLO WORLD EXAMPLE  Hello world example code you can found on below github link: https://github.com/bhargavlalo/ba-nodejs- example/blob/master/1-helloworld/1-helloworld.js
  • 16. NODE.JS ECOSYSTEM  Node.js heavily relies on modules, in previous examples require keyword loaded the http 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.
  • 17. BLOCKING I/O AND NON BLOCKING I/O  Traditional I/O var result = db.query(“select x from table_Y”); doSomethingWith(result); //wait for result! doSomethingWithOutResult(); //execution is blocked!  Non-traditional, Non-blocking I/O db.query(“select x from table_Y”,function (result){ doSomethingWith(result); //wait for result! }); doSomethingWithOutResult(); //executes without any delay!
  • 18. NON-BLOCKING EXAMPLE  Nonblocking example code: https://github.com/bhargavlalo/ba-nodejs- example/blob/master/4-nonblocking/nonblocking.js
  • 19. EXAMPLE TCP SERVER  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");
  • 20. EXAMPLE 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); }); });
  • 21. EXAMPLE TWITTER STREAMING  Install nTwitter module using npm: Npm install ntwitter  Code: var twitter = require('ntwitter'); var twit = new twitter({ consumer_key: ‘c_key’, consumer_secret: ‘c_secret’, access_token_key: ‘token_key’, access_token_secret: ‘token_secret’}); twit.stream('statuses/sample', function(stream) { stream.on('data', function (data) { console.log(data); }); });
  • 22. ADVANCE EXAMPLES  Some advance examples created on my github repo.  Below is the link https://github.com/bhargavlalo/ba-nodejs-example  Examples  Desktop Application  HTML Render  Node Mailer