Developing for Node.js
@debug_mode

Dhananjay Kumar
Agenda









What is this buzz Node
Create first HTTP Server : Demo
How Node works ?
Understanding EventLoop an...
Your Presenter
 Dhananjay Kumar
– Evangelist , Telerik
– Microsoft MVP
– Mentror C-Sharpcorner
– @debug_mode
– http://deb...
What is Node.js ?

Asynchronous Event Driven Server
Side JavaScript
Runs on Google JS V8 Engine
Non-blocking I/O and File ...
Demo : Create first web Server
Let us understand code line by line
Line 1

Line 4

•
•

•
•

•

Loading http module
It is required to work with HTTP
requ...
Let us understand code line by line
Line 9

Line 5-6
•
•
•

Writing data in response
Data can be written in form of
string...
How Node works ?
• It works on single thread
• It handles all request asynchronously
on same thread
• It does not create n...
Visual Studio and Node

Manage NPM Modules
Events in Node
• Each objects in Node emit an asynchronous
event.
• event is handled by an object EventEmitter.
• EventEmi...
Streams in Node
Demo on echo server

Demo on uploading file
asynchronously
Routers in Node
Modules to create Routers
Demo add routes using Crossroads

•
•
•
•
•

Express
Director
Bouncy
Backbone
Cr...
Demo : REST API on Node.js
•
•
•
•
•

Export data from a Module
Add routes in Express
Map routes to function
Test in fiddl...
Demo : REST API on Node.js
Step 1 : Create JSON Object Array
Demo : REST API on Node.js
Step 2 : Retrieve function
Demo : REST API on Node.js
Step 3 : Add function
Demo : REST API on Node.js
Step 4 : Update function
Demo : REST API on Node.js
Step 5 : Delete function
Demo : REST API on Node.js
Step 5 : Add Routes
Thanks & Questions?
@debug_mode
Upcoming SlideShare
Loading in …5
×

Node.js

2,163 views

Published on

Slides from Node.js talk

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,163
On SlideShare
0
From Embeds
0
Number of Embeds
990
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • https://nodejstools.codeplex.com/releases/view/114437 : download from here
  • https://nodejstools.codeplex.com/releases/view/114437 : download from here
  • Node.js

    1. 1. Developing for Node.js @debug_mode Dhananjay Kumar
    2. 2. Agenda         What is this buzz Node Create first HTTP Server : Demo How Node works ? Understanding EventLoop and Callback Create Echo Server : Demo Create app to upload large file asynchronously : Demo Create routers using Crossroads : Demo Create REST API using Express and Visual Studio : Demo
    3. 3. Your Presenter  Dhananjay Kumar – Evangelist , Telerik – Microsoft MVP – Mentror C-Sharpcorner – @debug_mode – http://debugmode.net – http://telerikhelper.net – Dhananjay.kumar@telerik.com
    4. 4. What is Node.js ? Asynchronous Event Driven Server Side JavaScript Runs on Google JS V8 Engine Non-blocking I/O and File API Highly Scalable Single Threaded Node Apps are created using JavaScript Faster in performance
    5. 5. Demo : Create first web Server
    6. 6. Let us understand code line by line Line 1 Line 4 • • • • • Loading http module It is required to work with HTTP request and response It is required to create HTTP Server Line 2 • • • • Create server using createServer() function It takes a callback as parameter . It takes HTTP request and response as paramtere Callback got two input parameter . Both input parameters are readable and writeable stream • Writing response header It takes a JSON object as optional second parameter second parameter contains informations like • • • • Content Length Content Type Connection Accept Type
    7. 7. Let us understand code line by line Line 9 Line 5-6 • • • Writing data in response Data can be written in form of string or buffer ServerResponse.end indicates the communication has been finished • • • Line 10 • Printing a message createServer() method is finished with chained http.Server.listen() method It specifies port number on which request will be listen Optional host name
    8. 8. How Node works ? • It works on single thread • It handles all request asynchronously on same thread • It does not create new thread for each request which is very unlikely like other web servers • It does not wait to complete a request Keep poling for event in EventLoop When gets event process asynchronously and assign a CallBack CallBack get executed once event execution is complete
    9. 9. Visual Studio and Node Manage NPM Modules
    10. 10. Events in Node • Each objects in Node emit an asynchronous event. • event is handled by an object EventEmitter. • EventEmitter is underneath every object.
    11. 11. Streams in Node Demo on echo server Demo on uploading file asynchronously
    12. 12. Routers in Node Modules to create Routers Demo add routes using Crossroads • • • • • Express Director Bouncy Backbone Crossroads
    13. 13. Demo : REST API on Node.js • • • • • Export data from a Module Add routes in Express Map routes to function Test in fiddler Use Visual Studio Template
    14. 14. Demo : REST API on Node.js Step 1 : Create JSON Object Array
    15. 15. Demo : REST API on Node.js Step 2 : Retrieve function
    16. 16. Demo : REST API on Node.js Step 3 : Add function
    17. 17. Demo : REST API on Node.js Step 4 : Update function
    18. 18. Demo : REST API on Node.js Step 5 : Delete function
    19. 19. Demo : REST API on Node.js Step 5 : Add Routes
    20. 20. Thanks & Questions? @debug_mode

    ×