nodejs tour
DESCRIPTION
Introduction on NodeJS at Refresh ColomboTRANSCRIPT
JavaScript on the Server Side
I’M ARUNODA
INTRODUCTION Framework to built Servers It’s about JavaScript Created by Ryan Dhal in 2009
ARCHITECTURE
Event LoopLibEV
Thread PoolLibIO
JS EngineV8
NodeJS bindings (http, socket, IO etc..)
JavaScript C++
PROGRAMMING MODEL Evented - No Threads Non Blocking IO Use of callbacks (closure)
db.insert({data: 1000}, function(err) { //do something after inserted})console.log("I don't wait");
SUPPORT Commercial –
Community – Mainly over Just 2 years old~2500 modules~800 authors~300 new modules per month~2000 new module updates per month
WEB AND NODEJS Websites
ConnectExpress
REST APIExpressGeddy
CommunicationSocket IONow JS (RPC)Dnode (RPC)
HTTP API - RESTler
EXPRESS - SAMPLE
var app = express.createServer(); app.get('/info', function(req, res){ res.send('Hello World');}); app.listen(3000);
NOWJS - SAMPLE
var server= require("http").createServer();
var nowjs = require("now");var remote= nowjs.initialize(httpServer); remote.now.getServerInfo = function(callback){ getInfo(callback);}server.listen(8000);
<script>now.getServerInfo(function(data){ //do something with the data});</script>
Server.js
Access.html
RESTLER - SAMPLE
var rest = require("restler"); rest.get("http://google.com").on("complete", function(data) { console.log(data);});
DATABASE SUPPORT
PACKAGE MANAGER It’s called NPM Like ivy But with JSON
npm install expressnpm publish
IDE It’s BAD No great debugger Cloud9 IDE Sublime Text 2
HOSTING
NODEJS EXPERIENCE Started 3 months back Rewritten Yalu on NodeJS Improved Performance
Projects on
USEFULL LINKS NodeJS Sri Lanka
bit.ly/nodelk
Node Linksbit.ly/node-info
THANKS Any Questions?