SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Node.js
BESHOY SEMSEM
Node.js
Node.js® is a JavaScript runtime built on
Chrome's V8 JavaScript engine. Node.js
uses an event-driven, non-blocking I/O
model that makes it lightweight and
efficient. Node.js' package ecosystem,
npm, is the largest ecosystem of open
source libraries in the world.
Why Use Node.js
1. You Already Know JavaScript
2. It's Fast
1. Node.js is a JavaScript runtime that uses the V8 engine
developed by Google for use in Chrome.
3.Tooling (NPM)
4.Real-time Made Easy
5.One Codebase And Your Real time For Free
1. https://www.meteor.com/
Nodejs installation
Node Version Manager
The Node Version Manager allows admins to easily manage
node.js versions. It’s a bash script that has the capability to
manage multiple active versions of node.js, with
functionality such as: installation, executing commands with
specific node.js versions, setting the PATH variable to use a
specific node.js versions
curl -o-
https://raw.githubusercontent.com/creationix/nvm/v0.31.0/i
nstall.sh | bash
Let us know. What is the
meaning of these commands?
 nvm install
 nvm use
 nvm current
 nvm ls
 nvm alias default
JavaScript & Node.js
Only in Javascript
window
location
document
Only in Node.js
global
process
module
Create Server
var http = require('http');
var handleRequest = function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Welcome to ITI Intake36 n');
};
var server = http.createServer(handleRequest);
server.listen(3000, 'localhost');
Create Server
var http = require('http');
To require modules
What is The difference between
var http = require('http');
AND
var http = require('./http');
Create Server
 function (req, res)
Res.writeHead
Res.writeHead
Res.end
Server.listen
Exports
exports vs module.exports
NPM
 npm install
 npm init
 npm publish
 npm login
 npm adduser
Callback
Node.js is a JavaScript runtime built on
Chrome's V8 JavaScript engine. Node.js
uses an event-driven, non-blocking I/O
mode
Callback is an asynchronous equivalent
for a function. A callback function is
called at the completion of a given task.
Callback
var fs = require("fs");
fs.readFile('input.txt', function (err, data) {
if (err) return console.error(err);
console.log(data.toString());
});
console.log("Program Ended");
callback
var fs = require("fs");
var data =
fs.readFileSync('input.txt');
console.log(data.toString());
console.log("Program Ended");
Streams
Streams are objects
that let you read
data from a source
or write data to a
destination in
continuous fashion.
In Node.js, there are four types of
streams
Readable - Stream which is used for read operation.
Writable - Stream which is used for write operation.
Duplex - Stream which can be used for both read
and write operation.
Transform - A type of duplex stream where the
output is computed based on input.
var fs = require("fs");
var data = '';
var readerStream = fs.createReadStream('input.txt');
readerStream.setEncoding('UTF8');
readerStream.on('data', function(chunk) {
data += chunk;
});
readerStream.on('end',function(){
console.log(data);
});
readerStream.on('error', function(err){
console.log(err.stack);
});
console.log("Program Ended");
Web Application
Architecture
Create own web server
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer( function (req, res) {
var pathname = url.parse(req.url).pathname;
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);
res.writeHead(404, {'Content-Type': 'text/html'});
}else{
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data.toString());
}
res.end();
});
}).listen(3000);
CONNECT TO DATA BASE
we will used mysql data base
and we will use mysql module
https://www.npmjs.com/package/mysql
CONNECT TO DATABASE
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'iti'
});
connection.query('SELECT * from books', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
Web service
A web service is any piece of
software that makes itself
available over the internet
REST
Representational State Transfer (REST) is
a software architecture style consisting of
guidelines and best practices for creating
scalable web services.
RESTful API HTTP methods
GET
POST
DELETE
PUT
Create web service
request
response
logic
format
Thank you :)
create server can handle crud
operation

Más contenido relacionado

La actualidad más candente

CRONtab Tutorial
CRONtab TutorialCRONtab Tutorial
CRONtab TutorialJoseph ...
 
Introduction to Erebos: a JavaScript client for Swarm
Introduction to Erebos: a JavaScript client for SwarmIntroduction to Erebos: a JavaScript client for Swarm
Introduction to Erebos: a JavaScript client for SwarmMiloš Mošić
 
Job Automation using Linux
Job Automation using LinuxJob Automation using Linux
Job Automation using LinuxJishnu Pradeep
 
Scylla Summit 2022: ScyllaDB Embraces Wasm
Scylla Summit 2022: ScyllaDB Embraces WasmScylla Summit 2022: ScyllaDB Embraces Wasm
Scylla Summit 2022: ScyllaDB Embraces WasmScyllaDB
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB ShellMongoDB
 
Script for the geomeetup presentation
Script for the geomeetup presentationScript for the geomeetup presentation
Script for the geomeetup presentationSteven Pousty
 
Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"EPAM Systems
 
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...Magento Meetup Wrocław
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lispfukamachi
 
Node.js streams talk
Node.js streams talkNode.js streams talk
Node.js streams talkzladuric
 
Glauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platformGlauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platformDon Marti
 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101Dvir Volk
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisKnoldus Inc.
 
Ansible Oxford - Cows & Containers
Ansible Oxford - Cows & ContainersAnsible Oxford - Cows & Containers
Ansible Oxford - Cows & Containersjonatanblue
 
Максим Барышиков-«WoT: Geographically distributed cluster of clusters»
Максим Барышиков-«WoT: Geographically distributed cluster of clusters»Максим Барышиков-«WoT: Geographically distributed cluster of clusters»
Максим Барышиков-«WoT: Geographically distributed cluster of clusters»Tanya Denisyuk
 

La actualidad más candente (20)

CRONtab Tutorial
CRONtab TutorialCRONtab Tutorial
CRONtab Tutorial
 
Introduction to Erebos: a JavaScript client for Swarm
Introduction to Erebos: a JavaScript client for SwarmIntroduction to Erebos: a JavaScript client for Swarm
Introduction to Erebos: a JavaScript client for Swarm
 
Job Automation using Linux
Job Automation using LinuxJob Automation using Linux
Job Automation using Linux
 
Cron
CronCron
Cron
 
Scylla Summit 2022: ScyllaDB Embraces Wasm
Scylla Summit 2022: ScyllaDB Embraces WasmScylla Summit 2022: ScyllaDB Embraces Wasm
Scylla Summit 2022: ScyllaDB Embraces Wasm
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB Shell
 
Script for the geomeetup presentation
Script for the geomeetup presentationScript for the geomeetup presentation
Script for the geomeetup presentation
 
Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"Владимир Мигуро "Дао Node.js"
Владимир Мигуро "Дао Node.js"
 
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
 
Building GUI App with Electron and Lisp
Building GUI App with Electron and LispBuilding GUI App with Electron and Lisp
Building GUI App with Electron and Lisp
 
Node.js streams talk
Node.js streams talkNode.js streams talk
Node.js streams talk
 
Comets notes
Comets notesComets notes
Comets notes
 
Glauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platformGlauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platform
 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & Tricks
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Ansible
AnsibleAnsible
Ansible
 
Ansible Oxford - Cows & Containers
Ansible Oxford - Cows & ContainersAnsible Oxford - Cows & Containers
Ansible Oxford - Cows & Containers
 
Node.js
Node.jsNode.js
Node.js
 
Максим Барышиков-«WoT: Geographically distributed cluster of clusters»
Максим Барышиков-«WoT: Geographically distributed cluster of clusters»Максим Барышиков-«WoT: Geographically distributed cluster of clusters»
Максим Барышиков-«WoT: Geographically distributed cluster of clusters»
 

Destacado

Brief introduction about GLOSHINE LED Screen Mfg
Brief introduction about GLOSHINE LED Screen MfgBrief introduction about GLOSHINE LED Screen Mfg
Brief introduction about GLOSHINE LED Screen MfgRachel chan
 
Paradigmas de la IA Trabajo
Paradigmas de la IA TrabajoParadigmas de la IA Trabajo
Paradigmas de la IA Trabajoandrea samudio
 
Colombia,conflicto,postconflicto y justicia transicional
Colombia,conflicto,postconflicto y justicia transicionalColombia,conflicto,postconflicto y justicia transicional
Colombia,conflicto,postconflicto y justicia transicionalJOSEESCRITOR
 

Destacado (8)

Faizan cv (1)
Faizan cv (1)Faizan cv (1)
Faizan cv (1)
 
Films noirs __pps_
Films noirs __pps_Films noirs __pps_
Films noirs __pps_
 
Brief introduction about GLOSHINE LED Screen Mfg
Brief introduction about GLOSHINE LED Screen MfgBrief introduction about GLOSHINE LED Screen Mfg
Brief introduction about GLOSHINE LED Screen Mfg
 
Ma patrie ml1
Ma patrie ml1Ma patrie ml1
Ma patrie ml1
 
Paradigmas de la IA Trabajo
Paradigmas de la IA TrabajoParadigmas de la IA Trabajo
Paradigmas de la IA Trabajo
 
Destination Marketing & Economic Development: Creating a Singular Place Brand
Destination Marketing & Economic Development: Creating a Singular Place BrandDestination Marketing & Economic Development: Creating a Singular Place Brand
Destination Marketing & Economic Development: Creating a Singular Place Brand
 
Rich trader
Rich traderRich trader
Rich trader
 
Colombia,conflicto,postconflicto y justicia transicional
Colombia,conflicto,postconflicto y justicia transicionalColombia,conflicto,postconflicto y justicia transicional
Colombia,conflicto,postconflicto y justicia transicional
 

Similar a Node36

Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami SayarFITC
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Lucas Jellema
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questionstechievarsity
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed AssafAhmed Assaf
 

Similar a Node36 (20)

Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Node js
Node jsNode js
Node js
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Node JS | Dilkash Shaikh Mahajan
Node JS | Dilkash Shaikh MahajanNode JS | Dilkash Shaikh Mahajan
Node JS | Dilkash Shaikh Mahajan
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
 
Exploring Node.jS
Exploring Node.jSExploring Node.jS
Exploring Node.jS
 
Node intro
Node introNode intro
Node intro
 
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
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
Book
BookBook
Book
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Event driven programming -- Node.JS
Event driven programming -- Node.JSEvent driven programming -- Node.JS
Event driven programming -- Node.JS
 
NodeJS
NodeJSNodeJS
NodeJS
 
React native
React nativeReact native
React native
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 

Último

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Último (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Node36

  • 2. Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
  • 3.
  • 4. Why Use Node.js 1. You Already Know JavaScript 2. It's Fast 1. Node.js is a JavaScript runtime that uses the V8 engine developed by Google for use in Chrome. 3.Tooling (NPM) 4.Real-time Made Easy 5.One Codebase And Your Real time For Free 1. https://www.meteor.com/
  • 5. Nodejs installation Node Version Manager The Node Version Manager allows admins to easily manage node.js versions. It’s a bash script that has the capability to manage multiple active versions of node.js, with functionality such as: installation, executing commands with specific node.js versions, setting the PATH variable to use a specific node.js versions curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/i nstall.sh | bash
  • 6. Let us know. What is the meaning of these commands?  nvm install  nvm use  nvm current  nvm ls  nvm alias default
  • 7. JavaScript & Node.js Only in Javascript window location document Only in Node.js global process module
  • 8.
  • 9. Create Server var http = require('http'); var handleRequest = function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Welcome to ITI Intake36 n'); }; var server = http.createServer(handleRequest); server.listen(3000, 'localhost');
  • 10.
  • 11. Create Server var http = require('http'); To require modules What is The difference between var http = require('http'); AND var http = require('./http');
  • 12. Create Server  function (req, res) Res.writeHead Res.writeHead Res.end Server.listen
  • 14.
  • 15. NPM  npm install  npm init  npm publish  npm login  npm adduser
  • 16. Callback Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O mode Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task.
  • 17. Callback var fs = require("fs"); fs.readFile('input.txt', function (err, data) { if (err) return console.error(err); console.log(data.toString()); }); console.log("Program Ended");
  • 18. callback var fs = require("fs"); var data = fs.readFileSync('input.txt'); console.log(data.toString()); console.log("Program Ended");
  • 19. Streams Streams are objects that let you read data from a source or write data to a destination in continuous fashion.
  • 20. In Node.js, there are four types of streams Readable - Stream which is used for read operation. Writable - Stream which is used for write operation. Duplex - Stream which can be used for both read and write operation. Transform - A type of duplex stream where the output is computed based on input.
  • 21. var fs = require("fs"); var data = ''; var readerStream = fs.createReadStream('input.txt'); readerStream.setEncoding('UTF8'); readerStream.on('data', function(chunk) { data += chunk; }); readerStream.on('end',function(){ console.log(data); }); readerStream.on('error', function(err){ console.log(err.stack); }); console.log("Program Ended");
  • 23. Create own web server
  • 24. var http = require('http'); var fs = require('fs'); var url = require('url'); http.createServer( function (req, res) { var pathname = url.parse(req.url).pathname; fs.readFile(pathname.substr(1), function (err, data) { if (err) { console.log(err); res.writeHead(404, {'Content-Type': 'text/html'}); }else{ res.writeHead(200, {'Content-Type': 'text/html'}); res.write(data.toString()); } res.end(); }); }).listen(3000);
  • 25. CONNECT TO DATA BASE we will used mysql data base and we will use mysql module https://www.npmjs.com/package/mysql
  • 26. CONNECT TO DATABASE var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'iti' }); connection.query('SELECT * from books', function(err, rows, fields) { if (err) throw err; console.log('The solution is: ', rows[0].solution); }); connection.end();
  • 27. Web service A web service is any piece of software that makes itself available over the internet
  • 28. REST Representational State Transfer (REST) is a software architecture style consisting of guidelines and best practices for creating scalable web services.
  • 29. RESTful API HTTP methods GET POST DELETE PUT
  • 31. Thank you :) create server can handle crud operation