SlideShare a Scribd company logo
INTRODUCTION TO
NODE.JS
Md Sohel Rana
About Me
Md. Sohel Rana
Founder, NerdDevs
http://www.nerddevs.com
twitter : @sohel023010
skype : sohel023010
https://github.com/sohel-rana
What is Node.js
 A runtime
environment to
support JavaScript
as server side
language
 Built on V8-
JavaScript Engine of
Chrome
 Event-driven, non-
blocking I/O
Node.js
 Advantages
- Asynchronous I/O, more requests can serve
- JavaScript as a Server Side language
- Event Driven
- A good package manager “NPM”
 Disadvantages
- Single threaded
- Long processing unit can lock down the
whole system
- Not elegant when more levels of callbacks
Installation
 Download the package from www.nodejs.org
website and install
Hello World!
 Open your favorite text editor and write,
console.log(‘Hello, World!’);
 Save the file as hello_world.js
 In terminal type node hello_world.js and you
should see this output
 Node.js is asynchronous
 Every I/O operation needs a callback
//reading host file
var fs = require('fs')
fs.readFile('/etc/hosts', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
console.log(data);
});
Callback
Web Server
An http server :
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(9000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:9000/');
Node Modules
 A functional unit that
performs specified
actions
 Loaded using
require(‘module_nam
e’)
 Reusability
Node Modules
A simple module :
// “modules/calculator.js”
exports.add = function(a, b){
return a+b ;
};
exports.subtract = function(a, b){
return a-b;
};
var Calculator = require('./module/calculator.js');
var addTwoNumber = Calculator.add(5,7);
console.log(addTwoNumber); // will print 12
NPM
 NPM- node.js
package manager
 Used to
install/uninstall
node programs
 Can be used to
install
dependencies
 package.json is
used to define
dependencies
//pakage.json
{
"name": "backbone-express-
boilerplate",
"version": "1.0.0",
"scripts": {
"start": "node ./server/bin/www"
},
"dependencies": {
"express": "^4.12.3",
"jade": "~1.9.2”
},
"repository": {
"type": "git",
"url": "https://<repo-url.>git"
},
"author": "Sohel Rana”,
"bugs": {
"url": "https://<repo-url>/issues"
},
"homepage": "https://<repo-
homepage>"
}
Supporting Databases
 Has support for
almost every
database
 SQL-Server,
MySQL,
PostgreSQL, Oracle
 Very often used with
MongoDB
Connecting with DB
 Install a driver(node_module) for the DB
 Import that module using require
 For MongoDB, we can use Mongoose
Connect with MongoDB
var mongoose = require('mongoose');
mongoose.connection.on('open', function (ref) {
console.log('Connected to mongo server.');
//do something here
});
mongoose.connection.on('error', function (err) {
console.log('Could not connect to mongo
server!');
console.log(err);
});
mongoose.connect('mongodb://localhost/mydb')
;
Web Frameworks
 NodeJS provides
core modules
 Requires lots of
effort for web apps
 Express, Sails etc.
provides lots of
feature top of it
 Makes the
maintenance easy
ExpressJS
 A complete web framework with routing
 Built-in REST API support
 Building API is quick and easy
 For installing, $npm install express --save
Express web app
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s',
host, port);
});
Express web app
 Running the app will show this
 If we visit http://localhost:3000 from browser,
we will see
Express web app
 Show some html
var express = require('express’);
var app = express();
app.use('/public', express.static('public'));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
Express web app
REST API
 An architectural style of building web services
 Uses http verbs GET, POST, PUT, DELETE
 Not a Protocol like SOAP
REST API in Express
 app.get(), app.post(), app.put(), app.delete()
 Some Examples
app.get('/user/:id', function(req, res){
res.send('user ' + req.params.id);
});
app.post('/save_user', function (req, res) {
//save user data
});
Hosting
 So many Cloud Platforms available
 Nodejitsu, appfog, Heroku, OpenShift
 NodeChef, EvenNode
 Microsoft Azure
Who are using
Future
 Getting popular for programming in IoT
 IBM, Microsoft investing
 Giant companies are using it
 NodeJS Foundation
Question?

More Related Content

What's hot (20)

PDF
Overview: How to Measure your WebApp
Chang W. Doh
 
ODP
Presentation of JSConf.eu
Fredrik Wendt
 
PDF
NodeJS: n00b no more
Ben Peachey
 
PPT
Top4top Showcase
ay4
 
PDF
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
rtCamp
 
PDF
Once upon a time, there were css, js and server-side rendering
Andrea Giannantonio
 
PDF
Compass VS Less
Sarah Hick
 
PDF
Node.jsやってみた
Yoshihiko Uchida
 
PPTX
Herramientas front
borya09
 
PPTX
Windows Azure loves OSS
Kazumi Hirose
 
PDF
JSConf US 2014: Building Isomorphic Apps
Spike Brehm
 
PPT
WebSockets and Java
Bozhidar Bozhanov
 
PPTX
A slightly advanced introduction to node.js
Sudar Muthu
 
PPTX
OW2 Nanoko
ClĂŠment Escoffier
 
PDF
Let s Enjoy Node.js
Fred Chien
 
PDF
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Atwix
 
PPTX
Node.js
Techizzaa
 
PDF
Browserify
davidchubbs
 
PDF
Virtual Infrastructure
Bryan McLellan
 
Overview: How to Measure your WebApp
Chang W. Doh
 
Presentation of JSConf.eu
Fredrik Wendt
 
NodeJS: n00b no more
Ben Peachey
 
Top4top Showcase
ay4
 
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
rtCamp
 
Once upon a time, there were css, js and server-side rendering
Andrea Giannantonio
 
Compass VS Less
Sarah Hick
 
Node.jsやってみた
Yoshihiko Uchida
 
Herramientas front
borya09
 
Windows Azure loves OSS
Kazumi Hirose
 
JSConf US 2014: Building Isomorphic Apps
Spike Brehm
 
WebSockets and Java
Bozhidar Bozhanov
 
A slightly advanced introduction to node.js
Sudar Muthu
 
OW2 Nanoko
ClĂŠment Escoffier
 
Let s Enjoy Node.js
Fred Chien
 
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Atwix
 
Node.js
Techizzaa
 
Browserify
davidchubbs
 
Virtual Infrastructure
Bryan McLellan
 

Similar to Introduction to node.js (20)

PPTX
Node js Introduction
sanskriti agarwal
 
PPTX
Introduction to node.js GDD
Sudar Muthu
 
PPTX
Introduction to Node.js
Winston Hsieh
 
PDF
Introduction to Node.js: What, why and how?
Christian Joudrey
 
PDF
Introduction to Node.js
Jack Franklin
 
PDF
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
PPTX
Introducing Node.js in an Oracle technology environment (including hands-on)
Lucas Jellema
 
PDF
An introduction to Node.js
Kasey McCurdy
 
PDF
What is Node.js? (ICON UK)
Tim Davis
 
PPT
nodejs_at_a_glance.ppt
WalaSidhom1
 
PPTX
Introduction to node.js by jiban
Jibanananda Sana
 
PPTX
Nodejs
Vinod Kumar Marupu
 
PPT
nodejs_at_a_glance, understanding java script
mohammedarshadhussai4
 
PPTX
Introduction to Node.js
Vikash Singh
 
PPTX
Starting with Node.js
Jitendra Zaa
 
PPTX
Kalp Corporate Node JS Perfect Guide
Kalp Corporate
 
PPTX
NodeJS - Server Side JS
Ganesh Kondal
 
PDF
Intro to Node.js
Jamal Sinclair O'Garro
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
PDF
Node.js for beginner
Sarunyhot Suwannachoti
 
Node js Introduction
sanskriti agarwal
 
Introduction to node.js GDD
Sudar Muthu
 
Introduction to Node.js
Winston Hsieh
 
Introduction to Node.js: What, why and how?
Christian Joudrey
 
Introduction to Node.js
Jack Franklin
 
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Lucas Jellema
 
An introduction to Node.js
Kasey McCurdy
 
What is Node.js? (ICON UK)
Tim Davis
 
nodejs_at_a_glance.ppt
WalaSidhom1
 
Introduction to node.js by jiban
Jibanananda Sana
 
nodejs_at_a_glance, understanding java script
mohammedarshadhussai4
 
Introduction to Node.js
Vikash Singh
 
Starting with Node.js
Jitendra Zaa
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate
 
NodeJS - Server Side JS
Ganesh Kondal
 
Intro to Node.js
Jamal Sinclair O'Garro
 
Intro to Node.js (v1)
Chris Cowan
 
Node.js for beginner
Sarunyhot Suwannachoti
 
Ad

Recently uploaded (20)

PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
July Patch Tuesday
Ivanti
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Ad

Introduction to node.js

  • 2. About Me Md. Sohel Rana Founder, NerdDevs http://www.nerddevs.com twitter : @sohel023010 skype : sohel023010 https://github.com/sohel-rana
  • 3. What is Node.js  A runtime environment to support JavaScript as server side language  Built on V8- JavaScript Engine of Chrome  Event-driven, non- blocking I/O
  • 4. Node.js  Advantages - Asynchronous I/O, more requests can serve - JavaScript as a Server Side language - Event Driven - A good package manager “NPM”  Disadvantages - Single threaded - Long processing unit can lock down the whole system - Not elegant when more levels of callbacks
  • 5. Installation  Download the package from www.nodejs.org website and install
  • 6. Hello World!  Open your favorite text editor and write, console.log(‘Hello, World!’);  Save the file as hello_world.js  In terminal type node hello_world.js and you should see this output
  • 7.  Node.js is asynchronous  Every I/O operation needs a callback //reading host file var fs = require('fs') fs.readFile('/etc/hosts', 'utf8', function (err, data) { if (err) { return console.log(err); } console.log(data); }); Callback
  • 8. Web Server An http server : var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(9000, '127.0.0.1'); console.log('Server running at http://127.0.0.1:9000/');
  • 9. Node Modules  A functional unit that performs specified actions  Loaded using require(‘module_nam e’)  Reusability
  • 10. Node Modules A simple module : // “modules/calculator.js” exports.add = function(a, b){ return a+b ; }; exports.subtract = function(a, b){ return a-b; }; var Calculator = require('./module/calculator.js'); var addTwoNumber = Calculator.add(5,7); console.log(addTwoNumber); // will print 12
  • 11. NPM  NPM- node.js package manager  Used to install/uninstall node programs  Can be used to install dependencies  package.json is used to define dependencies //pakage.json { "name": "backbone-express- boilerplate", "version": "1.0.0", "scripts": { "start": "node ./server/bin/www" }, "dependencies": { "express": "^4.12.3", "jade": "~1.9.2” }, "repository": { "type": "git", "url": "https://<repo-url.>git" }, "author": "Sohel Rana”, "bugs": { "url": "https://<repo-url>/issues" }, "homepage": "https://<repo- homepage>" }
  • 12. Supporting Databases  Has support for almost every database  SQL-Server, MySQL, PostgreSQL, Oracle  Very often used with MongoDB
  • 13. Connecting with DB  Install a driver(node_module) for the DB  Import that module using require  For MongoDB, we can use Mongoose
  • 14. Connect with MongoDB var mongoose = require('mongoose'); mongoose.connection.on('open', function (ref) { console.log('Connected to mongo server.'); //do something here }); mongoose.connection.on('error', function (err) { console.log('Could not connect to mongo server!'); console.log(err); }); mongoose.connect('mongodb://localhost/mydb') ;
  • 15. Web Frameworks  NodeJS provides core modules  Requires lots of effort for web apps  Express, Sails etc. provides lots of feature top of it  Makes the maintenance easy
  • 16. ExpressJS  A complete web framework with routing  Built-in REST API support  Building API is quick and easy  For installing, $npm install express --save
  • 17. Express web app var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  • 18. Express web app  Running the app will show this  If we visit http://localhost:3000 from browser, we will see
  • 19. Express web app  Show some html var express = require('express’); var app = express(); app.use('/public', express.static('public')); app.get('/', function (req, res) { res.sendFile(__dirname + '/index.html'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  • 21. REST API  An architectural style of building web services  Uses http verbs GET, POST, PUT, DELETE  Not a Protocol like SOAP
  • 22. REST API in Express  app.get(), app.post(), app.put(), app.delete()  Some Examples app.get('/user/:id', function(req, res){ res.send('user ' + req.params.id); }); app.post('/save_user', function (req, res) { //save user data });
  • 23. Hosting  So many Cloud Platforms available  Nodejitsu, appfog, Heroku, OpenShift  NodeChef, EvenNode  Microsoft Azure
  • 25. Future  Getting popular for programming in IoT  IBM, Microsoft investing  Giant companies are using it  NodeJS Foundation