SlideShare a Scribd company logo
Complete Guide On Node.js
By:
Senior Developer
Prabin Silwal
What you should know before?
Javascript
Unix command
Installation:3way to install
• 1st way: Nodejs.org :
– You can download pre-compiled binary
– Easy installation
– Automatic configured environment
– But, updates require reinstallation
– And switching versions need reinstallation
2nd way : Version manager(nvm):
Install any version quickly
Switch version quickly
Easy install on Linux
But no widzard based installation(must use
command line interface)
And reinstall global modules when switching version
Install version manager then node
3rd way : Compile it from source(node)
Get absolute new node
Customize your installation
But you must be familiar with compiling process
And takes longer
And not easy to switch
Which is preferable?
• For mine 2nd way
Window installation:
• Download node.js
• Click install
Checking after installation?
• Run command
• Type “node” and hit enter
• Type “console.log(‘your text’)”
Note that previous installation process
needs re installation for new updates.
Installing using nvm in Linux(Not
wizard mode for Linux):
Make ready to install by following
command:
• sudo apt-get install git
• sudo apt-get install curl
Install using command:
Why node.js ?
• It is js with browser
• JS for both front end and backend (eg: using
jquery)
• Native support
• It’s fast because it’s mostly C code
What can you build?
•
•
•
•

Websocket server ( Like chat server)
Fast file upload client
Ad server
Any Real- Time Data Apps
What is Node.js not:
• Web framework
• For Beginners (it’s very low level)
• Multi- threaded (You can think of it as a single
threaded server)
Few variables you are familiar about
web browser:
• window : (Type in console of chrome)
The window object have functions and
attributes that have to do something with
window being drawn in screen.
• location: (Type in console of chrome)
The location object has all the information about url
that being loaded.
• document : (Type in console of chrome)
The document object contains all oh html displayed
in page
Now type in node console:
• It displays undefined message
Why not work in node?
• Because node is not just an instance , so
“global” is defined in node but not in chrome
console where you can get instance version of
global object called window.
• This global object has several functions (which
are not in chrome console)
• EG: require function: used to pull in different
javascript script files from your appliction
But error in chrome console:
Some works on both:
• Eg: console
Note: local variable vs global
• Eg:
name = prabin; //global
Var name = prabin; //local
Node is Non-blocking: Blocking vs Noblocking 1
Blocking vs No-blocking 2
Blocking vs No-blocking 3
Callback alternate syntax:
MODULES
REQUIRING MODULES
var http = require('http'); //http.js
va r fs = require('fs'); // fs.js
How does ‘require’ return the libraries?
How does it find these files?
Custom Module Example:
• Prabin_App(base folder)
– Example.js
var say = require(‘./say_hello_module.js’); //say is assigned as object & has 2 properties :
softly and loudly which both are functions
say.softly(‘prabin’);
Say.loudly(‘PRABIN’);

– Say_hello_module(Module Folder)
• index.js
var hello = function (message)
{
console.log(‘say hello:’+message);
});
exports.slowly = hello;//we first declare hello as function and setting slowly to be value of
hello
exports.loudly = function(message)
{
console.log(‘SAY HELLO:’+message);
});
LETS CREATE OUR OWN MODULE
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
• For finding modules:
NPM: THE USERLAND SEA
“Core” is small. “Userland” is large.

Package manager for node
• Comes with node
• Module Repository
• Dependency Management
• Easily publish modules
• “Local Only”
INSTALLING A NPM MODULE
/Home/my_app
• $ npm install request
https://github.com/mikeal/request
Installs into local node_modules directory
---------------after installation------------------------------Home/my_app/node_modules/request
----For require/using in your app-----------------------------------/Home/my_app/app.js
va r request = require('request');//Loads from local
node_modules directory
LOCAL VS GLOBAL MODULE
• Install modules with executables globally:
$ npm install coffee-script –g //global
$ coffee app.coffee
Note: Global npm modules can’t be required

$ npm install coffee-script //Install locally
FINDING MODULES
• From npm command line:
$ npm search module_name
Eg: $ npm search request
DEFINING YOUR DEPENDENCIES
my_app/package.json
{
"name": "My App",
"version": "1",
"dependencies":
{
"connect": "1.8.7"
}
}
Then: $ npm install will installs it into the node_modules directory
i.e. my_app/node_modules/connect
• SEMANTIC VERSIONING:
Major Minor Patch
1 . 8 . 7
Test Time
NODE.JS : Hello world
Hello.js
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200); //Status code in browser
response.write("Hello World.");//ResponseText
response.end();//Close the connection
}).listen(8080);//Listen for connection on this port
console.log('Listening on port 8080...');
• Run the server:
$ node Hello.js
(Listening on port 8080...)
• View output
$ curl http://localhost:8080
(Hello World)
Event Loops 1
Event Loops 2
Long Running Process
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200);
response.write(“Hello World running.");
response.end();
setTimeout(function() //Represent long running process
{
response.write(" Hello World is done.");
response.end();
}, 5000);
//5000ms = 5 seconds
}).listen(8080);
TWO CALLBACKS HERE
var http = require('http');
request
http.createServer(function(request, response) {
response.writeHead(200);
response.write(“Hello World running.");
response.end();
timeout
setTimeout(function() //Represent long running process
{
response.write(" Hello World is done.");
response.end();
}, 5000);
//5000ms = 5 seconds
}).listen(8080);
TWO CALLBACKS TIMELINE
(With blocking timeline)
NOTE: TYPICAL BLOCKING THINGS
• Calls out to web services
• Reads/Writes on the Database
• Calls to extensions
EVENTS IN THE DOM
• The DOM triggers Events you can listen for
those events
EVENTS IN NODE 1
• Many objects in Node emit events
EVENTS IN NODE 2
Also there is custom EventEmitter
var EventEmitter = require('events').EventEmitter;
var http = require('http');

http.createServer(function(request, response){ ... });

But what is really going on here?
http://nodejs.org/api/
Breaking It down
var http = require('http');
ALTERNATE SYNTAX
Streams
STREAMING RESPONSE
Readable stream

Writable stream

http.createServer(function(request, response) {
response.writeHead(200);
response.write(“Hello World Writing.");

setTimeout(function()
{
response.write(" Hello World is done.");
response.end();

}, 5000);
}).listen(8080);

Output to client:
Hello World Writing.
(5 seconds later)
Hello World is done.
HOW TO READ FROM THE REQUEST?
$ curl -d 'hello' http://localhost:8080
Output on client: hello
READING AND WRITING A FILE
var fs = require('fs'); // require filesystem module
var file = fs.createReadStream("readme.md");
var newFile =
fs.createWriteStream("readme_copy.md");
require filesystem module
file.pipe(newFile);
UPLOAD A FILE
var fs = require('fs');
var http = require('http');
http.createServer(function(request, response) {
var newFile =
fs.createWriteStream("readme_copy.md");
request.on('end', function() {
response.end('uploaded!');
});
}).listen(8080);
On Client:
$ curl --upload-file readme.md http://localhost:8080
Output on client: uploaded!
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
DOCUMENTATION
http://nodejs.org/api/
REMEMBER THIS CODE 1?
var fs = require('fs');
var newFile = fs.createWriteStream("readme_copy.md");
var http = require('http');
http.createServer(function(request, response)
{
request.pipe(newFile);
request.on('end', function()
{
response.end('uploaded!');
});
}).listen(8080);
REMEMBER THIS CODE 2?
http.createServer(function(request, response) {
var newFile = fs.createWriteStream("readme_copy.md");
var fileBytes = request.headers['content-length'];
var uploadedBytes = 0;
request.pipe(newFile);
request.on('data', function(chunk)
{
uploadedBytes += chunk.length;
var progress = (uploadedBytes / fileBytes) * 100;
response.write("progress: " + parseInt(progress, 10) + "%n");
});
}).listen(8080);
Express
Express
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
SOCKET.IO
SOCKET.IO
• Traditional
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
Persisting Data
Persisting Data
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
A complete guide to Node.js
References:
• IN T R O T O N O D E . J S (Authorized site)
• Ihrig C. J. - Pro Node.js for Developers
• Gackenheimer C. - Node.js Recipes
Thank You
• Any Suggestions and queries :
Website: http://prabinsilwal.com.np
Email: silwalprabin@hotmail.com
Ad

More Related Content

What's hot (20)

Kubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of KubernetesKubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of Kubernetes
Mike Splain
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
Yevgeniy Brikman
 
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей МарченкоIaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
Sigma Software
 
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Timothy Appnel
 
Puppet Camp London Fall 2015 - Service Discovery and Puppet
Puppet Camp London Fall 2015 - Service Discovery and PuppetPuppet Camp London Fall 2015 - Service Discovery and Puppet
Puppet Camp London Fall 2015 - Service Discovery and Puppet
Marc Cluet
 
Consul - service discovery and others
Consul - service discovery and othersConsul - service discovery and others
Consul - service discovery and others
Walter Liu
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
Puppet
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
Puppet
 
Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modules
Yevgeniy Brikman
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
Workhorse Computing
 
Docker in practice
Docker in practiceDocker in practice
Docker in practice
Jonathan Giannuzzi
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
andymccurdy
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
Yurii Vasylenko
 
Ansible - A 'crowd' introduction
Ansible - A 'crowd' introductionAnsible - A 'crowd' introduction
Ansible - A 'crowd' introduction
Manuel de la Peña Peña
 
Amazon EC2 Container Service in Action
Amazon EC2 Container Service in ActionAmazon EC2 Container Service in Action
Amazon EC2 Container Service in Action
Remotty
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Nebulaworks
 
Host Health Monitoring with Docker Run
Host Health Monitoring with Docker RunHost Health Monitoring with Docker Run
Host Health Monitoring with Docker Run
Noah Zoschke
 
AWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp VaultAWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp Vault
Grzegorz Adamowicz
 
Ansible intro
Ansible introAnsible intro
Ansible intro
Marcelo Quintiliano da Silva
 
Kubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of KubernetesKubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of Kubernetes
Mike Splain
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
Yevgeniy Brikman
 
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей МарченкоIaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
Sigma Software
 
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Timothy Appnel
 
Puppet Camp London Fall 2015 - Service Discovery and Puppet
Puppet Camp London Fall 2015 - Service Discovery and PuppetPuppet Camp London Fall 2015 - Service Discovery and Puppet
Puppet Camp London Fall 2015 - Service Discovery and Puppet
Marc Cluet
 
Consul - service discovery and others
Consul - service discovery and othersConsul - service discovery and others
Consul - service discovery and others
Walter Liu
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
Puppet
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
Puppet
 
Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modules
Yevgeniy Brikman
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
andymccurdy
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
Yurii Vasylenko
 
Amazon EC2 Container Service in Action
Amazon EC2 Container Service in ActionAmazon EC2 Container Service in Action
Amazon EC2 Container Service in Action
Remotty
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Nebulaworks
 
Host Health Monitoring with Docker Run
Host Health Monitoring with Docker RunHost Health Monitoring with Docker Run
Host Health Monitoring with Docker Run
Noah Zoschke
 
AWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp VaultAWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp Vault
Grzegorz Adamowicz
 

Similar to A complete guide to Node.js (20)

Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
Local development environment evolution
Local development environment evolutionLocal development environment evolution
Local development environment evolution
Wise Engineering
 
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
Node.js essentials
 Node.js essentials Node.js essentials
Node.js essentials
Bedis ElAchèche
 
Node azure
Node azureNode azure
Node azure
Emanuele DelBono
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
Gary Yeh
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
Vincent Mercier
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 
Restarting app with Nodemon.pptx
Restarting app with Nodemon.pptxRestarting app with Nodemon.pptx
Restarting app with Nodemon.pptx
Lovely Professional University
 
Google Cloud Platform for DeVops, by Javier Ramirez @ teowaki
Google Cloud Platform for DeVops, by Javier Ramirez @ teowakiGoogle Cloud Platform for DeVops, by Javier Ramirez @ teowaki
Google Cloud Platform for DeVops, by Javier Ramirez @ teowaki
javier ramirez
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Nodejs
NodejsNodejs
Nodejs
Vinod Kumar Marupu
 
Automating That "Other" OS
Automating That "Other" OSAutomating That "Other" OS
Automating That "Other" OS
Julian Dunn
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
Rami Sayar
 
unit 2 of Full stack web development subject
unit 2 of Full stack web development subjectunit 2 of Full stack web development subject
unit 2 of Full stack web development subject
JeneferAlan1
 
Node.js
Node.jsNode.js
Node.js
krishnapriya Tadepalli
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
Ganesh Kondal
 
Node js
Node jsNode js
Node js
Rohan Chandane
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
Local development environment evolution
Local development environment evolutionLocal development environment evolution
Local development environment evolution
Wise Engineering
 
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
Gary Yeh
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
Vincent Mercier
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 
Google Cloud Platform for DeVops, by Javier Ramirez @ teowaki
Google Cloud Platform for DeVops, by Javier Ramirez @ teowakiGoogle Cloud Platform for DeVops, by Javier Ramirez @ teowaki
Google Cloud Platform for DeVops, by Javier Ramirez @ teowaki
javier ramirez
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Automating That "Other" OS
Automating That "Other" OSAutomating That "Other" OS
Automating That "Other" OS
Julian Dunn
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
Rami Sayar
 
unit 2 of Full stack web development subject
unit 2 of Full stack web development subjectunit 2 of Full stack web development subject
unit 2 of Full stack web development subject
JeneferAlan1
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
Ganesh Kondal
 
Ad

Recently uploaded (20)

Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Ad

A complete guide to Node.js

  • 1. Complete Guide On Node.js By: Senior Developer Prabin Silwal
  • 2. What you should know before? Javascript Unix command
  • 3. Installation:3way to install • 1st way: Nodejs.org : – You can download pre-compiled binary – Easy installation – Automatic configured environment – But, updates require reinstallation – And switching versions need reinstallation
  • 4. 2nd way : Version manager(nvm): Install any version quickly Switch version quickly Easy install on Linux But no widzard based installation(must use command line interface) And reinstall global modules when switching version Install version manager then node
  • 5. 3rd way : Compile it from source(node) Get absolute new node Customize your installation But you must be familiar with compiling process And takes longer And not easy to switch
  • 6. Which is preferable? • For mine 2nd way
  • 7. Window installation: • Download node.js • Click install
  • 8. Checking after installation? • Run command • Type “node” and hit enter • Type “console.log(‘your text’)”
  • 9. Note that previous installation process needs re installation for new updates.
  • 10. Installing using nvm in Linux(Not wizard mode for Linux):
  • 11. Make ready to install by following command: • sudo apt-get install git • sudo apt-get install curl
  • 13. Why node.js ? • It is js with browser • JS for both front end and backend (eg: using jquery) • Native support • It’s fast because it’s mostly C code
  • 14. What can you build? • • • • Websocket server ( Like chat server) Fast file upload client Ad server Any Real- Time Data Apps
  • 15. What is Node.js not: • Web framework • For Beginners (it’s very low level) • Multi- threaded (You can think of it as a single threaded server)
  • 16. Few variables you are familiar about web browser: • window : (Type in console of chrome) The window object have functions and attributes that have to do something with window being drawn in screen.
  • 17. • location: (Type in console of chrome) The location object has all the information about url that being loaded.
  • 18. • document : (Type in console of chrome) The document object contains all oh html displayed in page
  • 19. Now type in node console: • It displays undefined message
  • 20. Why not work in node? • Because node is not just an instance , so “global” is defined in node but not in chrome console where you can get instance version of global object called window.
  • 21. • This global object has several functions (which are not in chrome console) • EG: require function: used to pull in different javascript script files from your appliction
  • 22. But error in chrome console:
  • 23. Some works on both: • Eg: console
  • 24. Note: local variable vs global • Eg: name = prabin; //global Var name = prabin; //local
  • 25. Node is Non-blocking: Blocking vs Noblocking 1
  • 30. REQUIRING MODULES var http = require('http'); //http.js va r fs = require('fs'); // fs.js How does ‘require’ return the libraries? How does it find these files?
  • 31. Custom Module Example: • Prabin_App(base folder) – Example.js var say = require(‘./say_hello_module.js’); //say is assigned as object & has 2 properties : softly and loudly which both are functions say.softly(‘prabin’); Say.loudly(‘PRABIN’); – Say_hello_module(Module Folder) • index.js var hello = function (message) { console.log(‘say hello:’+message); }); exports.slowly = hello;//we first declare hello as function and setting slowly to be value of hello exports.loudly = function(message) { console.log(‘SAY HELLO:’+message); });
  • 32. LETS CREATE OUR OWN MODULE
  • 38. • For finding modules:
  • 39. NPM: THE USERLAND SEA “Core” is small. “Userland” is large. Package manager for node • Comes with node • Module Repository • Dependency Management • Easily publish modules • “Local Only”
  • 40. INSTALLING A NPM MODULE /Home/my_app • $ npm install request https://github.com/mikeal/request Installs into local node_modules directory ---------------after installation------------------------------Home/my_app/node_modules/request ----For require/using in your app-----------------------------------/Home/my_app/app.js va r request = require('request');//Loads from local node_modules directory
  • 41. LOCAL VS GLOBAL MODULE • Install modules with executables globally: $ npm install coffee-script –g //global $ coffee app.coffee Note: Global npm modules can’t be required $ npm install coffee-script //Install locally
  • 42. FINDING MODULES • From npm command line: $ npm search module_name Eg: $ npm search request
  • 43. DEFINING YOUR DEPENDENCIES my_app/package.json { "name": "My App", "version": "1", "dependencies": { "connect": "1.8.7" } } Then: $ npm install will installs it into the node_modules directory i.e. my_app/node_modules/connect
  • 44. • SEMANTIC VERSIONING: Major Minor Patch 1 . 8 . 7
  • 46. NODE.JS : Hello world Hello.js var http = require('http'); http.createServer(function(request, response) { response.writeHead(200); //Status code in browser response.write("Hello World.");//ResponseText response.end();//Close the connection }).listen(8080);//Listen for connection on this port console.log('Listening on port 8080...');
  • 47. • Run the server: $ node Hello.js (Listening on port 8080...) • View output $ curl http://localhost:8080 (Hello World)
  • 50. Long Running Process var http = require('http'); http.createServer(function(request, response) { response.writeHead(200); response.write(“Hello World running."); response.end(); setTimeout(function() //Represent long running process { response.write(" Hello World is done."); response.end(); }, 5000); //5000ms = 5 seconds }).listen(8080);
  • 51. TWO CALLBACKS HERE var http = require('http'); request http.createServer(function(request, response) { response.writeHead(200); response.write(“Hello World running."); response.end(); timeout setTimeout(function() //Represent long running process { response.write(" Hello World is done."); response.end(); }, 5000); //5000ms = 5 seconds }).listen(8080);
  • 54. NOTE: TYPICAL BLOCKING THINGS • Calls out to web services • Reads/Writes on the Database • Calls to extensions
  • 55. EVENTS IN THE DOM • The DOM triggers Events you can listen for those events
  • 56. EVENTS IN NODE 1 • Many objects in Node emit events
  • 58. Also there is custom EventEmitter var EventEmitter = require('events').EventEmitter;
  • 59. var http = require('http'); http.createServer(function(request, response){ ... }); But what is really going on here? http://nodejs.org/api/
  • 60. Breaking It down var http = require('http');
  • 63. STREAMING RESPONSE Readable stream Writable stream http.createServer(function(request, response) { response.writeHead(200); response.write(“Hello World Writing."); setTimeout(function() { response.write(" Hello World is done."); response.end(); }, 5000); }).listen(8080); Output to client: Hello World Writing. (5 seconds later) Hello World is done.
  • 64. HOW TO READ FROM THE REQUEST?
  • 65. $ curl -d 'hello' http://localhost:8080 Output on client: hello
  • 66. READING AND WRITING A FILE var fs = require('fs'); // require filesystem module var file = fs.createReadStream("readme.md"); var newFile = fs.createWriteStream("readme_copy.md"); require filesystem module file.pipe(newFile);
  • 67. UPLOAD A FILE var fs = require('fs'); var http = require('http'); http.createServer(function(request, response) { var newFile = fs.createWriteStream("readme_copy.md"); request.on('end', function() { response.end('uploaded!'); }); }).listen(8080); On Client: $ curl --upload-file readme.md http://localhost:8080 Output on client: uploaded!
  • 73. REMEMBER THIS CODE 1? var fs = require('fs'); var newFile = fs.createWriteStream("readme_copy.md"); var http = require('http'); http.createServer(function(request, response) { request.pipe(newFile); request.on('end', function() { response.end('uploaded!'); }); }).listen(8080);
  • 74. REMEMBER THIS CODE 2? http.createServer(function(request, response) { var newFile = fs.createWriteStream("readme_copy.md"); var fileBytes = request.headers['content-length']; var uploadedBytes = 0; request.pipe(newFile); request.on('data', function(chunk) { uploadedBytes += chunk.length; var progress = (uploadedBytes / fileBytes) * 100; response.write("progress: " + parseInt(progress, 10) + "%n"); }); }).listen(8080);
  • 111. References: • IN T R O T O N O D E . J S (Authorized site) • Ihrig C. J. - Pro Node.js for Developers • Gackenheimer C. - Node.js Recipes
  • 112. Thank You • Any Suggestions and queries : Website: http://prabinsilwal.com.np Email: [email protected]