2. About me:
• Senior Architect @ Sela
• Windows Azure MVP
• Co-manager of the Windows Azure
Community
• Co-author of Developing Windows Azure and
Web Services (MOC 20487)
• Developing software professionally since 1997
4. About 1997:
Script-based server side
Shared hosting environment
Browser wars
New HTML standard that will
“Change the World”
This guy was the PM of Israel
5. Agenda
• What is Node.js
• The Importance of Being Asynchronous
• NPM
• Connect Middleware
• Express
6. What is Node.js
• A JavaScript runtime that is designed for
asynchronous IO operations
• Very lightweight and fast
• In use by a growing number of companies:
7. The Node.js Ecosystem
• Node.js has a rapidly growing ecosystem:
– Web frameworks:
• Express.js
• Socket.io
– Database support:
• MongoDB
• SQL Server
– Hosting and Cloud environments:
• IIS, Azure
• Forever.js
• Joyent, Heroku
9. Synchronous server operations
// GET api/countries
public string Get()
{
var client = WebRequest.Create("http://.../");
var response = client.GetResponse();
var stream = response.GetResponseStream();
var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
11. Same-Same but Different
// GET api/countries
Public async Task<string> Get()
{
var client = new HttpClient();
var response = await client.GetAsync("http://...");
return await response.Content.ReadAsStringAsync();
}
14. Async JavaScript with Node.js
• Node.js is asynchronous by design
• Most IO operations have no synchronous API
• This is crucial since Node.js (or rather V8) has
a single thread
15. Node Package Manager (NPM)
• The Node Package Manager (NPM) provides a
management mechanism for modules
• Download and install
• Version management
• Deployment
17. Connect Middleware
• Node.js http module provides bare-bones HTTP server
functionality
• Connect middleware (by Sencha Labs) provides an expandable
pipeline on top of Node.js's httpServer
• You can add any functionality to the pipeline by calling the use
method, and passing a method:
server.use(function(req, res, next){
// some code
next();
})
21. ExpressJS
• ExpressJS is a web application framework
inspired by Ruby’s Sinatra
• Provides a model-view-route architecture
22. Routing
• Routing is one of the pillars of ExpressJS
• To create a route use the app.verb
convention:
app.get('route',function(req,res){
});
app.post('route',function(req,res){
});
app.all('route',function(req,res){
});
24. Routing and Parameters
• Express supports parameters as part of the URI
• Declare a parameter in the URI using a
placeholder
• Access query-string parameters using req.query
• Use regular expression
26. Configuring Express
• Express provides the configure method to perform
configuration:
• Setting up Connect middleware
• Setting up application level variables using
app.set
27. Views
• Views are a template-based UI mechanism
• Express supports many view-engines
including:
• Jade
• JSHtml
• EJS
28. Jade
• Jade is Express’s default view engine
• It is based on Haml in order to provide a clean
syntax for generating HTML
• Tab based
• Full support for HTML
32. Blocks
• In most applications, a number of UI
components are used throughout the
application
• Blocks provide a way to declare a common
layout that is shared among views
36. Summary
• Node.js allows JavaScript
to run outside of browsers
and perform IO
• Asynchronous by nature
• Lightweight, fast and
extremely cool
• Rich ecosystem for
building JavaScript-based
servers
37. What’s next
• ExpressJS can be used to
use the MVR/MVC
patterns in web
applications
• Currently there are
1688 projects in NPM
which use Express: Sails,
Express.io, etc.
• All you need is a text
editor and a command line
Notes de l'éditeur
Explain the basic node concepts:Modules and how we import them using requireThe use of callbacks
Explain the basic node concepts:Modules and how we import them using requireThe use of callbacks