SlideShare a Scribd company logo
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)
Ad

More Related Content

What's hot (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
Ganesh Iyer
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
Jeff Kunkle
 
Node ppt
Node pptNode ppt
Node ppt
Tamil Selvan R S
 
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 Express
David 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
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
Vatsal N Shah
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom 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 Programming
Kamal Hussain
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
jacekbecela
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom 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 API
Fabien Vauchelles
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
Ndjido Ardo BAR
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar 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 & Express
Christian Joudrey
 
NodeJS
NodeJSNodeJS
NodeJS
LinkMe Srl
 
Node.js essentials
 Node.js essentials Node.js essentials
Node.js essentials
Bedis ElAchèche
 
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
Ganesh Iyer
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
Jeff 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 Express
David 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.js
Vikash Singh
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom 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 Programming
Kamal Hussain
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
jacekbecela
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom 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 API
Fabien Vauchelles
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar 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 & Express
Christian Joudrey
 

Viewers also liked (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
Edureka!
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
Triet 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 Bergenhem
FITC
 
Pengenalan Dasar NodeJS
Pengenalan Dasar NodeJSPengenalan Dasar NodeJS
Pengenalan Dasar NodeJS
alfi setyadi
 
Node js overview
Node js overviewNode js overview
Node js overview
Eyal 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) platform
Sreenivas Kappala
 
Mengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaSMengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaS
The World Bank
 
single page application
single page applicationsingle page application
single page application
Ravindra K
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
Cipriano Freitas
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
Right IT Services
 
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
Tracy Lee
 
Single-Page Web Application Architecture
Single-Page Web Application ArchitectureSingle-Page Web Application Architecture
Single-Page Web Application Architecture
Eray 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 Express
Eueung Mulyana
 
EAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISEEAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISE
Vijay 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 Tutorial
PHP Support
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
Shravan Kumar Kasagoni
 
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
Tracy 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
 
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
Edureka!
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
Triet 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 Bergenhem
FITC
 
Pengenalan Dasar NodeJS
Pengenalan Dasar NodeJSPengenalan Dasar NodeJS
Pengenalan Dasar NodeJS
alfi setyadi
 
Node js overview
Node js overviewNode js overview
Node js overview
Eyal 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) platform
Sreenivas Kappala
 
Mengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaSMengembangkan Solusi Cloud dengan PaaS
Mengembangkan Solusi Cloud dengan PaaS
The World Bank
 
single page application
single page applicationsingle page application
single page application
Ravindra 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-cli
Tracy Lee
 
Single-Page Web Application Architecture
Single-Page Web Application ArchitectureSingle-Page Web Application Architecture
Single-Page Web Application Architecture
Eray 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 Express
Eueung Mulyana
 
EAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISEEAIESB TIBCO EXPERTISE
EAIESB TIBCO EXPERTISE
Vijay 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 Tutorial
PHP 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 Minutes
Tracy 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
 
Ad

Similar to 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
Laurence 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 workshop
leffen
 
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
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
Bruce 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
 
concept of server-side JavaScript / JS Framework: NODEJS
concept of server-side JavaScript / JS Framework: NODEJSconcept of server-side JavaScript / JS Framework: NODEJS
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
Enoch Joshua
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.js
Md. Sohel Rana
 
Node.js
Node.jsNode.js
Node.js
krishnapriya Tadepalli
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
Sureshreddy Nalimela
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
Tim Fairweather
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
Gianluca Padovani
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Su 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 Assaf
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
Gary Yeh
 
Proposal
ProposalProposal
Proposal
Constantine Priemski
 
Nodejs
NodejsNodejs
Nodejs
Vinod Kumar Marupu
 
nodejs_at_a_glance, understanding java script
nodejs_at_a_glance, understanding java scriptnodejs_at_a_glance, understanding java script
nodejs_at_a_glance, understanding java script
mohammedarshadhussai4
 
Nodejs
NodejsNodejs
Nodejs
dssprakash
 
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
Laurence 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 workshop
leffen
 
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
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
Bruce 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 beginners
Enoch Joshua
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.js
Md. Sohel Rana
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
Tim Fairweather
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Su 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 Assaf
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
Gary Yeh
 
nodejs_at_a_glance, understanding java script
nodejs_at_a_glance, understanding java scriptnodejs_at_a_glance, understanding java script
nodejs_at_a_glance, understanding java script
mohammedarshadhussai4
 
Ad

More from 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!
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 Course
Rohan 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 far
Rohan Chandane
 
Backbone js
Backbone jsBackbone js
Backbone js
Rohan Chandane
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
Rohan Chandane
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)
Rohan Chandane
 
J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
Rohan Chandane
 
Parsing XML in J2ME
Parsing XML in J2MEParsing XML in J2ME
Parsing XML in J2ME
Rohan Chandane
 
J2ME RMS
J2ME RMSJ2ME RMS
J2ME RMS
Rohan Chandane
 
J2ME IO Classes
J2ME IO ClassesJ2ME IO Classes
J2ME IO Classes
Rohan Chandane
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2ME
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 Course
Rohan 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 far
Rohan Chandane
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
Rohan Chandane
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
Rohan 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-J2ME
Rohan Chandane
 

Recently uploaded (20)

To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
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
 
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
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
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
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
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
 
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
 
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)
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
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
 
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
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
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
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
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
 
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
 

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