17
JavaScript on the Server Side

NodeJS Tour

Embed Size (px)

DESCRIPTION

Introduction on NodeJS at Refresh Colombo

Citation preview

Page 1: NodeJS Tour

JavaScript on the Server Side

Page 2: NodeJS Tour

I’M ARUNODA

Page 3: NodeJS Tour

INTRODUCTION Framework to built Servers It’s about JavaScript Created by Ryan Dhal in 2009

Page 4: NodeJS Tour

ARCHITECTURE

Event LoopLibEV

Thread PoolLibIO

JS EngineV8

NodeJS bindings (http, socket, IO etc..)

JavaScript C++

Page 5: NodeJS Tour

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");

Page 6: NodeJS Tour

SUPPORT Commercial –

Community – Mainly over Just 2 years old~2500 modules~800 authors~300 new modules per month~2000 new module updates per month

Page 7: NodeJS Tour

WEB AND NODEJS Websites

ConnectExpress

REST APIExpressGeddy

CommunicationSocket IONow JS (RPC)Dnode (RPC)

HTTP API - RESTler

Page 8: NodeJS Tour

EXPRESS - SAMPLE

var app = express.createServer(); app.get('/info', function(req, res){ res.send('Hello World');}); app.listen(3000);

Page 9: NodeJS Tour

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

Page 10: NodeJS Tour

RESTLER - SAMPLE

var rest = require("restler"); rest.get("http://google.com").on("complete", function(data) { console.log(data);});

Page 11: NodeJS Tour

DATABASE SUPPORT

Page 12: NodeJS Tour

PACKAGE MANAGER It’s called NPM Like ivy But with JSON

npm install expressnpm publish

Page 13: NodeJS Tour

IDE It’s BAD No great debugger Cloud9 IDE Sublime Text 2

Page 14: NodeJS Tour

HOSTING

Page 15: NodeJS Tour

NODEJS EXPERIENCE Started 3 months back Rewritten Yalu on NodeJS Improved Performance

Projects on

Page 16: NodeJS Tour

USEFULL LINKS NodeJS Sri Lanka

bit.ly/nodelk

Node Linksbit.ly/node-info

Page 17: NodeJS Tour

THANKS Any Questions?