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

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

What's hot (20)

Overview: How to Measure your WebApp
Overview: How to Measure your WebAppOverview: How to Measure your WebApp
Overview: How to Measure your WebApp
 
Node JS
Node JSNode JS
Node JS
 
Presentation of JSConf.eu
Presentation of JSConf.euPresentation of JSConf.eu
Presentation of JSConf.eu
 
NodeJS: n00b no more
NodeJS: n00b no moreNodeJS: n00b no more
NodeJS: n00b no more
 
Top4top Showcase
Top4top ShowcaseTop4top Showcase
Top4top Showcase
 
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
EasyEngine - Command-Line tool to manage WordPress Sites on NginxEasyEngine - Command-Line tool to manage WordPress Sites on Nginx
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
 
Once upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side renderingOnce upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side rendering
 
Compass VS Less
Compass VS LessCompass VS Less
Compass VS Less
 
Node.jsやってみた
Node.jsやってみたNode.jsやってみた
Node.jsやってみた
 
Herramientas front
Herramientas frontHerramientas front
Herramientas front
 
Windows Azure loves OSS
Windows Azure loves OSSWindows Azure loves OSS
Windows Azure loves OSS
 
JSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic AppsJSConf US 2014: Building Isomorphic Apps
JSConf US 2014: Building Isomorphic Apps
 
WebSockets and Java
WebSockets and JavaWebSockets and Java
WebSockets and Java
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
 
OW2 Nanoko
OW2 NanokoOW2 Nanoko
OW2 Nanoko
 
Let s Enjoy Node.js
Let s Enjoy Node.jsLet s Enjoy Node.js
Let s Enjoy Node.js
 
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
 
Node.js
Node.jsNode.js
Node.js
 
Browserify
BrowserifyBrowserify
Browserify
 
Virtual Infrastructure
Virtual InfrastructureVirtual Infrastructure
Virtual Infrastructure
 

Similar to Introduction to node.js

Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
Jitendra Zaa
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
Sreenivas Kappala
 
Nodejs
NodejsNodejs
Nodejs
dssprakash
 
Node js
Node jsNode js
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Proposal
ProposalProposal
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
Nodejs
NodejsNodejs
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar Muthu
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
node.js - Fast event based web application development
node.js - Fast event based web application developmentnode.js - Fast event based web application development
node.js - Fast event based web application development
openForce Information Technology GesmbH
 
NodeJS
NodeJSNodeJS
NodeJS
LinkMe Srl
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
dipen55
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
Edureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
Edureka!
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
async_io
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
sanskriti agarwal
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
Bruce Li
 

Similar to Introduction to node.js (20)

Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
 
Nodejs
NodejsNodejs
Nodejs
 
Node js
Node jsNode js
Node js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Proposal
ProposalProposal
Proposal
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Nodejs
NodejsNodejs
Nodejs
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
node.js - Fast event based web application development
node.js - Fast event based web application developmentnode.js - Fast event based web application development
node.js - Fast event based web application development
 
NodeJS
NodeJSNodeJS
NodeJS
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
 

Recently uploaded

Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 

Recently uploaded (20)

Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 

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