SlideShare une entreprise Scribd logo
1  sur  29
Node js
with npm,
installing express js
@RohanChandane

Last updated on 13th Oct 2013
Installing Node
nodejs.org
Hello World
...

On windows machine,
- Setting up environment variable is built in inside nodejs
directory
- after installation, type nodevars to install environment variable.
nodevars.bat is a batch file responsible for setting it up
What is Node / Node js?
- Node is Command line tool
- Download it and install
- It runs javascript code by typing ‘node your-script-file.js’

- Hosted on V8 Javascript engine
- uses V8 as standalone engine to execute javascript.

- Server-side javascript
- Node provides JavaScript API to access network & file system.
- These JavaScript files runs on the server rather than on the client side
- We can also write a server, which can be a replacement for something like
the Apache web server
...
- Uses event-driven I/O (non-blocking I/O)
- is just a term that describes the normal asynchronous callback
mechanisms.
- In node.js you supply callback functions for all sorts of things, and your
function is called when the relevant event occurs.
- So that means, it works parallelly on different I/O operations.
- eg. Code for reading from a file & reading values from a database can be
executed one after another (since node js is single threaded), and it will wait for
data to receive from file & database.
Once it receives data, it will call callback function related to function call.

- One language
- to write server side and client side code
- No need to learn server side language like Java & PHP
Why Node
1. Efficiency
- Response time
= server-side script execution time + time taken for I/O operation

- Node reduces the response time to the duration it takes to execute
the slowest I/O query
- Its mainly because ‘Single threaded - Event loop’
- Also called Event driven computing Architecture

- There is a need for high performance web servers
...
2. JavaScript
- JavaScript is universal language for web
developers
- Its single threaded
- Its dynamic

3. Speed
- Up till now, JavaScript was related to
browser
- We used it for DOM manipulation
- and our favourite browser to execute
javascript, is Chrome
...
- Chrome uses V8 engine
underneath to execute js
- V8 is the fastest javascript
execution engine
- V8 was designed to run in
Chrome’s multi-process model

V8 engine

- V8 is intended to be used both in a browser
and as a standalone high-performance engine
Asynchronous callback mechanisms
4. callbacks are invoked

functions, which are initiating
- I/O operations
- writing to a socket
- making a database query
& not going to return the value
immediately

event loop

3. event occurs

1. registers callbacks

2. loop wait for events

There's a single thread, and a single event loop, that handles all IO in node.js
Writing Server-side js with Node
Now, lets see how to write a server in
JavaScript
- creating 'server.js'
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

- executing it:
node server.js
Passing function as parameter
lets say
function execute(someFunction, value) {
someFunction(value);
}
execute(function(word){ console.log(word) }, "Hello");

can also be written
function say(word) {
console.log(word);
}
function execute(someFunction, value) {
someFunction(value);
}
execute(say, "Hello");
Understanding server.js
var http = require("http");
function onRequest(request, response) {
console.log("Callback invoked");
response.writeHead(200, {"Content-Type":
"text/plain"});
response.write("Hello World");
response.end();
}
1
2
http.createServer(onRequest).listen(8888);
console.log("Server started");

3

4
single thread
...
This ‘server.js’ program executes in following
order
1. registers callbacks

onRequest

2. loop wait for events

listen(8888)

3. event occurs

Browser requests - localhost:8888

4. callbacks are invoked

function onRequest() gets execute
Some Basic Core Modules
Node has several modules compiled into the binary. Defined in node's
source in the lib/ folder. To load use require('modules identifier')

- HTTP

how to use require('http')

- Net

how to use require('net')

- DNS

how to use require('dns')

- Events

how to use require('events')

- Utilities

how to use require('util')

- File System

how to use require('fs')

- Operating System

how to use require('os')

- Debugger

how to use debugger
Some Global object
Available in all modules

- Console

how to use console

- Process

how to use process

- Exports

how to use exports

- require

how to use require()

- setTimeout

how to use setTimeout()

- clearTimeout

how to use clearTimeout()

- setInterval

how to use setInterval()

- clearInterval

how to use clearInterval()
Core Modules: usage
Net require('net')
- Asynchronous network wrapper. It can create server & Client.
- Following example program creates server. It can be connected
using Telnet/Putty & responds to all user provided data.
var sys = require("sys"),
net = require("net");
var server = net.createServer(function(stream) {
stream.setEncoding("utf8");
stream.addListener("connect", function() {
stream.write("Client connectedn");
});
stream.addListener("data", function(data) {
stream.write("Received from client: " + data);
stream.write(data);
});
});
server.listen(8000, "localhost");
Node Package Manager
NPM: npmjs.org
Node Package Manager (NPM)
- Node modules largely written in JavaScript which runs on the server
(executed by the V8 engine) rather than on the client side.
- These modules are registered in npm registry at registry.npmjs.org
- To use these modules while developing application, npm helps in
- installing Node js packages / Modules / Programs
- & linking their dependencies

- npm is a command line utility program
- npm is bundled and installed automatically with Node version 0.6.3 and
above
- On windows, after setting up environment variables npm command can
be executed from any desired location to install node packages
NPM Commands
npm -l
- display full usage info
npm <command> -h
- display quick help on command
- eg npm install -h
npm faq
- commonly asked questions
npm ls
- displays all versions of available packages installed on system, their
dependencies, in tree structure
…
npm install <module name>
- to install new modules
- on windows, command prompt should be running with admin rights
npm install <module name> -g
- to install new modules globally
- on windows at location C:Users<user>AppDataRoamingnpm
...
npm update
- update all listed packages to their latest version (in given folder)
- install missing packages
- removes old versions of packages
npm update -g
- update all listed global packages
npm update <pkg>
- update specific package
express js
Installing node module: express js
- express js
- Web application framework for node js
- Provides robust set of features to build single and multi page, &
hybrid web application

- installing express js on windows
- Start cmd with admin rights
- Make sure you have set up environment variable for node js
- Go to your project directory and type npm install express
...
- installing express as global package
- Previously we installed express for particular folder
- But usually we install it globally
- To install express globally, type npm install express -g

- On windows, this will install express in
C:Users<user>AppDataRoamingnpm
- express js is ready to use now
...
- Create a express project
- Inside project directory type express and enter
- This will create a project structure and will display created files,
what are dependencies and how to run project

- This is instructing to install dependencies by staying in same
directory and type npm install
...
- Run express server
- To run this newly created project, type node app

- Go to browser and type localhost:3000

And now you can start editing
code to make it the way you
want.
...
- While setting up project
- you can pass certain parameters to choose templating engine
and stylesheet engine

- for example, following command will create project with support
for ‘less’ stylesheet and ‘ejs’ templating
express -c less -e
Off course it need to install dependencies
References
http://en.wikipedia.org/wiki/V8_(JavaScript_engine)
http://stackoverflow.com/questions/6632606/where-does-node-js-fit-within-theweb-development-context
http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef70f7ecbdd56cb
http://www.nodebeginner.org/
http://howtonode.org/
https://npmjs.org/
http://nodejs.org/
Book:
Node: Up & Running - Tom Hughes-Croucher & Mike Wilson (O’reilly)

Contenu connexe

Tendances

Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsGanesh Iyer
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js ExplainedJeff Kunkle
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)iFour Technolab Pvt. Ltd.
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS ExpressDavid Boyer
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Christian Joudrey
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialTom Croucher
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsjacekbecela
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & ExpressChristian Joudrey
 

Tendances (20)

Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
 
Node ppt
Node pptNode ppt
Node ppt
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node.js essentials
 Node.js essentials Node.js essentials
Node.js essentials
 

En vedette

Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppEdureka!
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting startedTriet Ho
 
Node.js – ask us anything!
Node.js – ask us anything! Node.js – ask us anything!
Node.js – ask us anything! Dev_Events
 
Building A Web App In 100% JavaScript with Carl Bergenhem
 Building A Web App In 100% JavaScript with Carl Bergenhem Building A Web App In 100% JavaScript with Carl Bergenhem
Building A Web App In 100% JavaScript with Carl BergenhemFITC
 
Pengenalan Dasar NodeJS
Pengenalan Dasar NodeJSPengenalan Dasar NodeJS
Pengenalan Dasar NodeJSalfi setyadi
 
Node js overview
Node js overviewNode js overview
Node js overviewEyal Vardi
 
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) platformSreenivas Kappala
 
Mengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaSMengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaSThe World Bank
 
single page application
single page applicationsingle page application
single page applicationRavindra K
 
The Tale of 2 CLIs - Ember-cli and Angular-cli
The Tale of 2 CLIs - Ember-cli and Angular-cliThe Tale of 2 CLIs - Ember-cli and Angular-cli
The Tale of 2 CLIs - Ember-cli and Angular-cliTracy Lee
 
Single-Page Web Application Architecture
Single-Page Web Application ArchitectureSingle-Page Web Application Architecture
Single-Page Web Application ArchitectureEray Arslan
 
Angular 2 + TypeScript = true. Let's Play!
Angular 2 + TypeScript = true. Let's Play!Angular 2 + TypeScript = true. Let's Play!
Angular 2 + TypeScript = true. Let's Play!Sirar Salih
 
Introduction to Node.JS Express
Introduction to Node.JS ExpressIntroduction to Node.JS Express
Introduction to Node.JS ExpressEueung Mulyana
 
EAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISEEAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISEVijay Reddy
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialPHP Support
 
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesUsing Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesTracy Lee
 
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...Tracy Lee
 

En vedette (20)

Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
Node.js – ask us anything!
Node.js – ask us anything! Node.js – ask us anything!
Node.js – ask us anything!
 
Building A Web App In 100% JavaScript with Carl Bergenhem
 Building A Web App In 100% JavaScript with Carl Bergenhem Building A Web App In 100% JavaScript with Carl Bergenhem
Building A Web App In 100% JavaScript with Carl Bergenhem
 
Pengenalan Dasar NodeJS
Pengenalan Dasar NodeJSPengenalan Dasar NodeJS
Pengenalan Dasar NodeJS
 
Node js overview
Node js overviewNode js overview
Node js overview
 
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
 
Mengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaSMengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaS
 
single page application
single page applicationsingle page application
single page application
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
 
The Tale of 2 CLIs - Ember-cli and Angular-cli
The Tale of 2 CLIs - Ember-cli and Angular-cliThe Tale of 2 CLIs - Ember-cli and Angular-cli
The Tale of 2 CLIs - Ember-cli and Angular-cli
 
Single-Page Web Application Architecture
Single-Page Web Application ArchitectureSingle-Page Web Application Architecture
Single-Page Web Application Architecture
 
Angular 2 + TypeScript = true. Let's Play!
Angular 2 + TypeScript = true. Let's Play!Angular 2 + TypeScript = true. Let's Play!
Angular 2 + TypeScript = true. Let's Play!
 
Introduction to Node.JS Express
Introduction to Node.JS ExpressIntroduction to Node.JS Express
Introduction to Node.JS Express
 
EAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISEEAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISE
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
 
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesUsing Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
 
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
 

Similaire à Node js

Introduction to Node js for beginners + game project
Introduction to Node js for beginners + game projectIntroduction to Node js for beginners + game project
Introduction to Node js for beginners + game projectLaurence Svekis ✔
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)Ashish Gupta
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopleffen
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for startersBruce Li
 
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
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.jsMd. Sohel Rana
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them AllTim Fairweather
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsSu Zin Kyaw
 
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
 
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.jsGary Yeh
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
 

Similaire à Node js (20)

Introduction to Node js for beginners + game project
Introduction to Node js for beginners + game projectIntroduction to Node js for beginners + game project
Introduction to Node js for beginners + game project
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
 
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
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.js
 
Node.js
Node.jsNode.js
Node.js
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
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
 
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
 
Proposal
ProposalProposal
Proposal
 
Nodejs
NodejsNodejs
Nodejs
 
Nodejs
NodejsNodejs
Nodejs
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
NodeJS @ ACS
NodeJS @ ACSNodeJS @ ACS
NodeJS @ ACS
 

Plus de Rohan Chandane

Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Rohan Chandane
 
Agile & Scrum, Certified Scrum Master! Crash Course
Agile & Scrum,  Certified Scrum Master! Crash CourseAgile & Scrum,  Certified Scrum Master! Crash Course
Agile & Scrum, Certified Scrum Master! Crash CourseRohan Chandane
 
An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications Rohan Chandane
 
Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so farRohan Chandane
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideRohan Chandane
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Rohan Chandane
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2MERohan Chandane
 

Plus de Rohan Chandane (13)

Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!
 
Agile & Scrum, Certified Scrum Master! Crash Course
Agile & Scrum,  Certified Scrum Master! Crash CourseAgile & Scrum,  Certified Scrum Master! Crash Course
Agile & Scrum, Certified Scrum Master! Crash Course
 
An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
 
Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so far
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)
 
J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
 
Parsing XML in J2ME
Parsing XML in J2MEParsing XML in J2ME
Parsing XML in J2ME
 
J2ME RMS
J2ME RMSJ2ME RMS
J2ME RMS
 
J2ME IO Classes
J2ME IO ClassesJ2ME IO Classes
J2ME IO Classes
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2ME
 

Dernier

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
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 byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Dernier (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
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 byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Node js

  • 1. Node js with npm, installing express js @RohanChandane Last updated on 13th Oct 2013
  • 4. ... On windows machine, - Setting up environment variable is built in inside nodejs directory - after installation, type nodevars to install environment variable. nodevars.bat is a batch file responsible for setting it up
  • 5. What is Node / Node js? - Node is Command line tool - Download it and install - It runs javascript code by typing ‘node your-script-file.js’ - Hosted on V8 Javascript engine - uses V8 as standalone engine to execute javascript. - Server-side javascript - Node provides JavaScript API to access network & file system. - These JavaScript files runs on the server rather than on the client side - We can also write a server, which can be a replacement for something like the Apache web server
  • 6. ... - Uses event-driven I/O (non-blocking I/O) - is just a term that describes the normal asynchronous callback mechanisms. - In node.js you supply callback functions for all sorts of things, and your function is called when the relevant event occurs. - So that means, it works parallelly on different I/O operations. - eg. Code for reading from a file & reading values from a database can be executed one after another (since node js is single threaded), and it will wait for data to receive from file & database. Once it receives data, it will call callback function related to function call. - One language - to write server side and client side code - No need to learn server side language like Java & PHP
  • 7. Why Node 1. Efficiency - Response time = server-side script execution time + time taken for I/O operation - Node reduces the response time to the duration it takes to execute the slowest I/O query - Its mainly because ‘Single threaded - Event loop’ - Also called Event driven computing Architecture - There is a need for high performance web servers
  • 8. ... 2. JavaScript - JavaScript is universal language for web developers - Its single threaded - Its dynamic 3. Speed - Up till now, JavaScript was related to browser - We used it for DOM manipulation - and our favourite browser to execute javascript, is Chrome
  • 9. ... - Chrome uses V8 engine underneath to execute js - V8 is the fastest javascript execution engine - V8 was designed to run in Chrome’s multi-process model V8 engine - V8 is intended to be used both in a browser and as a standalone high-performance engine
  • 10. Asynchronous callback mechanisms 4. callbacks are invoked functions, which are initiating - I/O operations - writing to a socket - making a database query & not going to return the value immediately event loop 3. event occurs 1. registers callbacks 2. loop wait for events There's a single thread, and a single event loop, that handles all IO in node.js
  • 11. Writing Server-side js with Node Now, lets see how to write a server in JavaScript - creating 'server.js' var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888); - executing it: node server.js
  • 12. Passing function as parameter lets say function execute(someFunction, value) { someFunction(value); } execute(function(word){ console.log(word) }, "Hello"); can also be written function say(word) { console.log(word); } function execute(someFunction, value) { someFunction(value); } execute(say, "Hello");
  • 13. Understanding server.js var http = require("http"); function onRequest(request, response) { console.log("Callback invoked"); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); } 1 2 http.createServer(onRequest).listen(8888); console.log("Server started"); 3 4 single thread
  • 14. ... This ‘server.js’ program executes in following order 1. registers callbacks onRequest 2. loop wait for events listen(8888) 3. event occurs Browser requests - localhost:8888 4. callbacks are invoked function onRequest() gets execute
  • 15. Some Basic Core Modules Node has several modules compiled into the binary. Defined in node's source in the lib/ folder. To load use require('modules identifier') - HTTP how to use require('http') - Net how to use require('net') - DNS how to use require('dns') - Events how to use require('events') - Utilities how to use require('util') - File System how to use require('fs') - Operating System how to use require('os') - Debugger how to use debugger
  • 16. Some Global object Available in all modules - Console how to use console - Process how to use process - Exports how to use exports - require how to use require() - setTimeout how to use setTimeout() - clearTimeout how to use clearTimeout() - setInterval how to use setInterval() - clearInterval how to use clearInterval()
  • 17. Core Modules: usage Net require('net') - Asynchronous network wrapper. It can create server & Client. - Following example program creates server. It can be connected using Telnet/Putty & responds to all user provided data. var sys = require("sys"), net = require("net"); var server = net.createServer(function(stream) { stream.setEncoding("utf8"); stream.addListener("connect", function() { stream.write("Client connectedn"); }); stream.addListener("data", function(data) { stream.write("Received from client: " + data); stream.write(data); }); }); server.listen(8000, "localhost");
  • 19. NPM: npmjs.org Node Package Manager (NPM) - Node modules largely written in JavaScript which runs on the server (executed by the V8 engine) rather than on the client side. - These modules are registered in npm registry at registry.npmjs.org - To use these modules while developing application, npm helps in - installing Node js packages / Modules / Programs - & linking their dependencies - npm is a command line utility program - npm is bundled and installed automatically with Node version 0.6.3 and above - On windows, after setting up environment variables npm command can be executed from any desired location to install node packages
  • 20. NPM Commands npm -l - display full usage info npm <command> -h - display quick help on command - eg npm install -h npm faq - commonly asked questions npm ls - displays all versions of available packages installed on system, their dependencies, in tree structure
  • 21. … npm install <module name> - to install new modules - on windows, command prompt should be running with admin rights npm install <module name> -g - to install new modules globally - on windows at location C:Users<user>AppDataRoamingnpm
  • 22. ... npm update - update all listed packages to their latest version (in given folder) - install missing packages - removes old versions of packages npm update -g - update all listed global packages npm update <pkg> - update specific package
  • 24. Installing node module: express js - express js - Web application framework for node js - Provides robust set of features to build single and multi page, & hybrid web application - installing express js on windows - Start cmd with admin rights - Make sure you have set up environment variable for node js - Go to your project directory and type npm install express
  • 25. ... - installing express as global package - Previously we installed express for particular folder - But usually we install it globally - To install express globally, type npm install express -g - On windows, this will install express in C:Users<user>AppDataRoamingnpm - express js is ready to use now
  • 26. ... - Create a express project - Inside project directory type express and enter - This will create a project structure and will display created files, what are dependencies and how to run project - This is instructing to install dependencies by staying in same directory and type npm install
  • 27. ... - Run express server - To run this newly created project, type node app - Go to browser and type localhost:3000 And now you can start editing code to make it the way you want.
  • 28. ... - While setting up project - you can pass certain parameters to choose templating engine and stylesheet engine - for example, following command will create project with support for ‘less’ stylesheet and ‘ejs’ templating express -c less -e Off course it need to install dependencies