JavaScript, Meet Cloud: Node.js on Windows Azure
-
Upload
sasha-goldshtein -
Category
Technology
-
view
2.870 -
download
4
Transcript of JavaScript, Meet Cloud: Node.js on Windows Azure
© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
Sasha Goldshtein @goldshtnCTO, SELA Group blog.sashag.netJavaScript, Meet Cloud: Node.js on Windows Azure
Node.js?
Lightweight JavaScript server with a rich module ecosystem running on Azure as a web site or a service
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.
What is Node.js
JavaScript on the serverUses the Google V8 engineHigh-speed JavaScript JIT and GC
Hundreds of modules, vibrant ecosystemPackage manager, including dependenciesHTTP(S), TCP, UDP server and clientBindings and ORMs for virtually every DBMVC framework (express)
Everything is open source
Why Node?
Cross-platformIt’s the next hip thing (after RoR)Asynchronous but no explicit concurrencyRapid developmentTiny footprint
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);
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);
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' }, ...);
Node on Azure Web Sites
Put your code in app.js or server.jsDeploy using Git, Mercurial, TFS, FTP, WebDeploy, DropboxUse modules freely with package.jsonDebug your website with node-inspectorNEW
msnodesql
var sql = require('msnodesql');
sql.query(conn_str, 'SELECT * FROM Messages', function (err, results) { if (!err) ... });
sql.queryRaw(conn_str, 'INSERT INTO Messages ...');
Node with SQL Database
Create an SQL databaseGet a connection stringOpen the firewall (if testing from premises)Node away!
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(...));
Node with Table Storage
Windows Azure Table Storage is a lightweight, super-cheap, NoSQL data store
Rows have dynamic propertiesSingle primary key (index)
var q = azure.TableQuery.select().from('messages');
tableService.queryEntities( q, function (err, results) ...);
tableService.insertEntity('messages', newMsg, ...);
Node on Azure Virtual Machines
Install whatever you wantPick from Windows or Linux distros
Microsoft open VMDepot offers dozens of images
We’ll use MongoDB on UbuntuAnd Mongoose for an ORMvar db = mongoose.createConnection(...);
var Message = db.model('Message', schema);
Message.find(function (err, results) ...);
Node Editor in The Cloud
Visual Studio Online “Monaco”NEW is a cloud IDE for your Node/ASP.NET Azure web sites