SlideShare a Scribd company logo
Node.js Introduction
2014/12/05
Winston Hsieh
What is Node.js?
 A platform built on Chrome’s JavaScript runtime for easily
building fast, scalable network applications.
 Node.js uses an event-driven, non-blocking I/O model that
makes it lightweight and efficient, perfect for data-intensive real-
time applications that run across distributed devices.
Build on JavaScript
 Developers can write web applications in one language.
 Reducing the context switch between client and server
development
 JSON is a very popular data interchange format today and is
native to JavaScript.
 JavaScript is the language used in various NoSQL databases
 Such as CouchDB and MongoDB
 JavaScript is a compilation target, and there are a number of
languages that compile to it already.
 See the “List of languages that compile to JS”.
Asynchronous and Event-driven
 Asynchronous I/O using JavaScript
 Node provides an event-driven and asynchronous platform for
server-side JavaScript
 Take this common snippet of jQuery performing an Ajax request
using XMLHttp-Request (XHR ):
 Notice that the code was not written like this:
$.post('/resource.json', function (data) {
console.log(data);
});
// script execution continues
var data = $.post('/resource.json');
console.log(data);
An example of non-blocking I/O in
the browser
Asynchronous and Event-driven
 I/O is almost always performed outside of the main event loop,
allowing the server to stay efficient and responsive,
 Here’s an example of how it looks in PHP :
 Execution stops until DB query completes
 Implement in Node.js:
$result = mysql_query('SELECT * FROM myTable');
print_r($result);
db.query('SELECT * FROM myTable', function(err, rows) {
if (err) throw err;
console.log(rows);
// do other thing
});
DIRTy Applications
 What’s meant by DIRTy applications, and why they’re a good fit
for Node
 There actually is an acronym for the types of applications Node is
designed for: DIRT
 It stands for data-intensive real-time applications
 Node itself is very lightweight on I/O
 It allows a server to hold a number of connections open while
handling many requests and keeping a small memory footprint
 Platform vs. framework
 Node is a platform for JavaScript applications, and it’s not to be
confused with a framework.
 A popular framework one for Node called Express
The lifecycle of an HTTP request
HTTP Server Fundamentals
 A basic HTTP server that responds with “Hello World”
 Reading request headers and setting response headers
 Setting the status code of an HTTP response
var http = require('http');
var server = http.createServer(function(req, res){
res.end('Hello World');
});
server.listen(3000);
var body = 'Hello World';
res.setHeader('Content-Length', body.length);
res.setHeader('Content-Type', 'text/plain');
res.end(body);
var url = 'http://google.com';
var body = ‘<p>Redirecting to <a href=“’ + url + ‘”>’ + url + '</a></p>';
res.setHeader('Location', url);
res.setHeader('Content-Length', body.length);
res.setHeader('Content-Type', 'text/html');
res.statusCode = 302;
res.end(body);
Building a RESTful Web Service
 In 2000, representational state transfer (REST) was introduced
by Roy Fielding, one of the prominent contributors to the HTTP
1.0 and 1.1 specifications
 http://zh.wikipedia.org/wiki/REST
 Suppose you want to create a to-do list web service with Node,
involving the typical create, read, update, and delete (CRUD)
actions
 HTTP verbs, such as GET, POST, PUT, and DELETE, are
mapped to retrieving, creating, updating, and removing the
resources specified by the URL
 Each verb will cover a different task for the to-do list:
 POST —Add items to the to-do list
 GET —Display a listing of the current items, or display the details of
a specific item
 DELETE —Remove items from the to-do list
 PUT —Should modify existing
CRUD - Create
 Creating resources with POST requests
CRUD - Create
 Concatenating data events to buffer the request body
CRUD - Read
 Fetching resources with GET requests
 Result:
CRUD - Delete
 Removing resources with DELETE requests
MongoDB (1)
 MongoDB is a general-purpose nonrelational database.
 A MongoDB database stores documents in collections.
 Documents in a collection need not share the same schema—
each document could conceivably have a different schema.
MongoDB (2)
 Install this module using the following npm command.
 Connecting to MongoDB
 Accessing a MongoDB collection
> npm install mongodb
var mongodb = require('mongodb');
var server = new mongodb.Server('127.0.0.1', 27017, {});
var client = new mongodb.Db('mydatabase', server, {w: 1});
client.open(function(err) {
if (err) throw err;
client.collection('test_insert', function(err, collection) {
if (err) throw err;
console.log('We are now able to perform queries.');
});
});
MongoDB (3)
 Insert a document into a collection
 Safe mode – Specifying {safe: true} in a query indicates that you
want the database operation to complete before executing the
callback.
collection.insert(
{
"title": "I like cake",
"body": "It is quite good."
},
{safe: true},
function(err, documents) {
if (err) throw err;
console.log('Document ID is: ' + documents[0]._id);
});
MongoDB (4)
 Updating, and deleting
var _id = new client.bson_serializer
.ObjectID('4e650d344ac74b5a01000001');
collection.update(
{_id: _id},
{$set: {"title": "I ate too much cake"}},
{safe: true},
function(err) {
if (err) throw err;
}
);
collection.remove({_id: _id}, {safe: true}, function(err) {
if (err) throw err;
});
Express (1)
 Install Express globally with npm
 npm install express
 Generate the application
 Explore the application and install dependencies
Express (2)
Express (3)
 Express has a minimalistic environment-driven configuration
system, consisting of five methods, all driven by the
NODE_ENV environment variable:
 app.configure()
 app.set()
 app.get()
 app.enable()
 app.disable()
 These environment names are completely arbitrary. For
example, you may have development , stage , test , and
production , or prod for short.
 Using conditionals to set environment-specific options
Express (4)
 Rendering views
 HTML template plus data = HTML view of data
 View system configuration
• Changing the lookup directory
• __dirname (with two leading underscores) is a global variable in Node that
identifies the directory in which the currently running file exists. Often in
development this directory will be the same as your current working directory
(CWD), but in production the Node executable may run from another
directory. Using __dirname helps keep paths consistent across environments.
Express (5)
 Default Template Engine
• Specifying the template engine using a file extension
 Keeping package.json in Sync
• Keep in mind that any additional template engines you wish to use should be
added to your package.json dependencies object.
Express (6)
 View Caching
• The view caching setting is enabled by default in the production environment
and prevents subsequent render() calls from performing disk I/O.
 View Lookup
Express (7)
 Exposing data to views
Express (8)
 A view template to list photos
 HTML produced by the photos/index.ejs template
Reference
 eBooks – Node.js in Action
 http://vk.com/doc205367072_271634724
 Code Example
 http://www.manning-source.com/books/cantelon/code_Node.js.zip
Ad

More Related Content

What's hot (20)

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
 
8 Most Effective Node.js Tools for Developers
8 Most Effective Node.js Tools for Developers8 Most Effective Node.js Tools for Developers
8 Most Effective Node.js Tools for Developers
iMOBDEV Technologies Pvt. Ltd.
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash Course
Haim Michael
 
Nodejs server lesson 3
 Nodejs server lesson 3 Nodejs server lesson 3
Nodejs server lesson 3
SamuelAdetunji2
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
Jeetendra singh
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
Node js
Node jsNode js
Node js
umesh patil
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
Triet Ho
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
ravisankar munusamy
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Pragnesh Vaghela
 
Node js
Node jsNode js
Node js
Krishna Chaytaniah
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
Naresh Chintalcheru
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
Jeff Kunkle
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
Jibanananda Sana
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Binary Studio
 
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
 
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
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash Course
Haim Michael
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
Jeetendra singh
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
Triet Ho
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
Naresh Chintalcheru
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
Jeff Kunkle
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
Jibanananda Sana
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Binary Studio
 
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
 

Similar to Introduction to Node.js (20)

Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
Native REST Web Services with Oracle 11g
Native REST Web Services with Oracle 11gNative REST Web Services with Oracle 11g
Native REST Web Services with Oracle 11g
Marcelo Ochoa
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
Sureshreddy Nalimela
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
Enoch Joshua
 
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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
techievarsity
 
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
 
mern _stack _power _point_ presentation(1)
mern _stack _power _point_ presentation(1)mern _stack _power _point_ presentation(1)
mern _stack _power _point_ presentation(1)
susmithalanka2
 
Exploring Node.jS
Exploring Node.jSExploring Node.jS
Exploring Node.jS
Deepu S Nath
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
Ayush Mishra
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
rani marri
 
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
 
Node JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHatNode JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHat
Scholarhat
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
Nir Noy
 
ODF Mashups
ODF MashupsODF Mashups
ODF Mashups
Alexandro Colorado
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
Google Developer Students Club NIT Silchar
 
Node JS | Dilkash Shaikh Mahajan
Node JS | Dilkash Shaikh MahajanNode JS | Dilkash Shaikh Mahajan
Node JS | Dilkash Shaikh Mahajan
DilkashShaikhMahajan
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
Native REST Web Services with Oracle 11g
Native REST Web Services with Oracle 11gNative REST Web Services with Oracle 11g
Native REST Web Services with Oracle 11g
Marcelo Ochoa
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
Enoch Joshua
 
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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
techievarsity
 
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
 
mern _stack _power _point_ presentation(1)
mern _stack _power _point_ presentation(1)mern _stack _power _point_ presentation(1)
mern _stack _power _point_ presentation(1)
susmithalanka2
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
Ayush Mishra
 
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
 
Node JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHatNode JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHat
Scholarhat
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
Nir Noy
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
Ad

Recently uploaded (20)

Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Ad

Introduction to Node.js

  • 2. What is Node.js?  A platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications.  Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real- time applications that run across distributed devices.
  • 3. Build on JavaScript  Developers can write web applications in one language.  Reducing the context switch between client and server development  JSON is a very popular data interchange format today and is native to JavaScript.  JavaScript is the language used in various NoSQL databases  Such as CouchDB and MongoDB  JavaScript is a compilation target, and there are a number of languages that compile to it already.  See the “List of languages that compile to JS”.
  • 4. Asynchronous and Event-driven  Asynchronous I/O using JavaScript  Node provides an event-driven and asynchronous platform for server-side JavaScript  Take this common snippet of jQuery performing an Ajax request using XMLHttp-Request (XHR ):  Notice that the code was not written like this: $.post('/resource.json', function (data) { console.log(data); }); // script execution continues var data = $.post('/resource.json'); console.log(data);
  • 5. An example of non-blocking I/O in the browser
  • 6. Asynchronous and Event-driven  I/O is almost always performed outside of the main event loop, allowing the server to stay efficient and responsive,  Here’s an example of how it looks in PHP :  Execution stops until DB query completes  Implement in Node.js: $result = mysql_query('SELECT * FROM myTable'); print_r($result); db.query('SELECT * FROM myTable', function(err, rows) { if (err) throw err; console.log(rows); // do other thing });
  • 7. DIRTy Applications  What’s meant by DIRTy applications, and why they’re a good fit for Node  There actually is an acronym for the types of applications Node is designed for: DIRT  It stands for data-intensive real-time applications  Node itself is very lightweight on I/O  It allows a server to hold a number of connections open while handling many requests and keeping a small memory footprint  Platform vs. framework  Node is a platform for JavaScript applications, and it’s not to be confused with a framework.  A popular framework one for Node called Express
  • 8. The lifecycle of an HTTP request
  • 9. HTTP Server Fundamentals  A basic HTTP server that responds with “Hello World”  Reading request headers and setting response headers  Setting the status code of an HTTP response var http = require('http'); var server = http.createServer(function(req, res){ res.end('Hello World'); }); server.listen(3000); var body = 'Hello World'; res.setHeader('Content-Length', body.length); res.setHeader('Content-Type', 'text/plain'); res.end(body); var url = 'http://google.com'; var body = ‘<p>Redirecting to <a href=“’ + url + ‘”>’ + url + '</a></p>'; res.setHeader('Location', url); res.setHeader('Content-Length', body.length); res.setHeader('Content-Type', 'text/html'); res.statusCode = 302; res.end(body);
  • 10. Building a RESTful Web Service  In 2000, representational state transfer (REST) was introduced by Roy Fielding, one of the prominent contributors to the HTTP 1.0 and 1.1 specifications  http://zh.wikipedia.org/wiki/REST  Suppose you want to create a to-do list web service with Node, involving the typical create, read, update, and delete (CRUD) actions  HTTP verbs, such as GET, POST, PUT, and DELETE, are mapped to retrieving, creating, updating, and removing the resources specified by the URL  Each verb will cover a different task for the to-do list:  POST —Add items to the to-do list  GET —Display a listing of the current items, or display the details of a specific item  DELETE —Remove items from the to-do list  PUT —Should modify existing
  • 11. CRUD - Create  Creating resources with POST requests
  • 12. CRUD - Create  Concatenating data events to buffer the request body
  • 13. CRUD - Read  Fetching resources with GET requests  Result:
  • 14. CRUD - Delete  Removing resources with DELETE requests
  • 15. MongoDB (1)  MongoDB is a general-purpose nonrelational database.  A MongoDB database stores documents in collections.  Documents in a collection need not share the same schema— each document could conceivably have a different schema.
  • 16. MongoDB (2)  Install this module using the following npm command.  Connecting to MongoDB  Accessing a MongoDB collection > npm install mongodb var mongodb = require('mongodb'); var server = new mongodb.Server('127.0.0.1', 27017, {}); var client = new mongodb.Db('mydatabase', server, {w: 1}); client.open(function(err) { if (err) throw err; client.collection('test_insert', function(err, collection) { if (err) throw err; console.log('We are now able to perform queries.'); }); });
  • 17. MongoDB (3)  Insert a document into a collection  Safe mode – Specifying {safe: true} in a query indicates that you want the database operation to complete before executing the callback. collection.insert( { "title": "I like cake", "body": "It is quite good." }, {safe: true}, function(err, documents) { if (err) throw err; console.log('Document ID is: ' + documents[0]._id); });
  • 18. MongoDB (4)  Updating, and deleting var _id = new client.bson_serializer .ObjectID('4e650d344ac74b5a01000001'); collection.update( {_id: _id}, {$set: {"title": "I ate too much cake"}}, {safe: true}, function(err) { if (err) throw err; } ); collection.remove({_id: _id}, {safe: true}, function(err) { if (err) throw err; });
  • 19. Express (1)  Install Express globally with npm  npm install express  Generate the application  Explore the application and install dependencies
  • 21. Express (3)  Express has a minimalistic environment-driven configuration system, consisting of five methods, all driven by the NODE_ENV environment variable:  app.configure()  app.set()  app.get()  app.enable()  app.disable()  These environment names are completely arbitrary. For example, you may have development , stage , test , and production , or prod for short.  Using conditionals to set environment-specific options
  • 22. Express (4)  Rendering views  HTML template plus data = HTML view of data  View system configuration • Changing the lookup directory • __dirname (with two leading underscores) is a global variable in Node that identifies the directory in which the currently running file exists. Often in development this directory will be the same as your current working directory (CWD), but in production the Node executable may run from another directory. Using __dirname helps keep paths consistent across environments.
  • 23. Express (5)  Default Template Engine • Specifying the template engine using a file extension  Keeping package.json in Sync • Keep in mind that any additional template engines you wish to use should be added to your package.json dependencies object.
  • 24. Express (6)  View Caching • The view caching setting is enabled by default in the production environment and prevents subsequent render() calls from performing disk I/O.  View Lookup
  • 25. Express (7)  Exposing data to views
  • 26. Express (8)  A view template to list photos  HTML produced by the photos/index.ejs template
  • 27. Reference  eBooks – Node.js in Action  http://vk.com/doc205367072_271634724  Code Example  http://www.manning-source.com/books/cantelon/code_Node.js.zip