Sasha Goldshtein discusses running Node.js applications on Microsoft's Azure cloud platform. Node.js allows for building lightweight JavaScript web servers and services that can take advantage of Azure's services like SQL Database, MongoDB, Redis, and mobile backends. The document provides examples of using Node.js with Azure services like SQL Database, Table Storage, and Virtual Machines running MongoDB. It also introduces Visual Studio Online's new Node.js editor for developing Azure web applications in the cloud.
3. The New Microsoft
You can run a Node.js web service on an Ubuntu
VM on Windows Azure that uses Redis for
caching, MongoDB for sessions, and an SQL
Database for most models. Oh, and you can
integrate it with a Windows Store or iPhone app.
4. What is Node.js
JavaScript on the server
Uses the Google V8 engine
High-speed JavaScript JIT and GC
Hundreds of modules, vibrant ecosystem
Package manager, including dependencies
HTTP(S), TCP, UDP server and client
Bindings and ORMs for virtually every DB
MVC framework (express)
Everything is open source
5. Why Node?
Cross-platform
It’s the next hip thing (after RoR)
Asynchronous but no explicit concurrency
Rapid development
Tiny footprint
6. Hello, Node
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200,
{'Content-Type’: 'text/plain'});
res.end('Hello, Node!n');
});
server.listen(8080);
7. express
var express = require('express');
var app = express.createServer();
app.get('/hello', function (req, res) {
res.sendfile('hello.htm');
});
app.post('/echo', function (req, res) {
res.end('You said: ' + req.body.message);
});
app.listen(8080);
8. nstore
var nstore = require('nstore');
var messages = nstore.new('messages.db', ...);
messages.save(msg.id, msg, function (err) ...);
messages.all(function (err, results) {
...
});
messages.find({ user: 'Sasha' }, ...);
9. Node on Azure Web Sites
Put your code in app.js or server.js
Deploy using
Git, Mercurial, TFS, FTP, WebDeploy, Dropbox
Use modules freely with package.json
Debug your website with node-inspectorNEW
10. msnodesql
var sql = require('msnodesql');
sql.query(conn_str, 'SELECT * FROM Messages',
function (err, results) {
if (!err) ...
}
);
sql.queryRaw(conn_str, 'INSERT INTO Messages ...');
11. Node with SQL Database
Create an SQL database
Get a connection string
Open the firewall (if testing from premises)
Node away!
12. Shared DB with Mobile Services
While we’re at it …
Windows Azure Mobile Services makes
implementing backends a breeze
You can share a DB
var table = MobileService.GetTable<Message>();
var messages = table.Where(
m => m.User == "Sasha").ToList();
await table.InsertAsync(new Message(...));
13. Node with Table Storage
Windows Azure Table Storage is a
lightweight, super-cheap, NoSQL data store
Rows have dynamic properties
Single primary key (index)
var q = azure.TableQuery.select().from('messages');
tableService.queryEntities(
q, function (err, results) ...);
tableService.insertEntity('messages', newMsg, ...);
14. Node on Azure Virtual Machines
Install whatever you want
Pick from Windows or Linux distros
Microsoft open VMDepot offers dozens of images
We’ll use MongoDB on Ubuntu
And Mongoose for an ORM
var db = mongoose.createConnection(...);
var Message = db.model('Message', schema);
Message.find(function (err, results) ...);
15. Node Editor in The Cloud
Visual Studio Online “Monaco”NEW is a cloud
IDE for your Node/ASP.NET Azure web sites