JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka

Post on 28-Jan-2015

110 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

JSCon 2011, arranged by phpXperts. held in American International University Bangladesh.

Transcript

NodeJSJS as a Server-side Language

NewsCred

Iraj Islam @irajislam

Nurul Ferdous @ferdous

Saturday, September 17, 2011

Agenda

• Part 1. NodeJS

• Part 2. ExpressJS

• Questions?

NewsCred

Saturday, September 17, 2011

Who We Are NewsCred

Iraj IslamCTO/Co-founder, NewsCred

Nurul FerdousSenior Software Engineer, NewsCred

Saturday, September 17, 2011

Part 1NodeJS

NewsCred

Saturday, September 17, 2011

Server-side JS NewsCred

Saturday, September 17, 2011

What’s NodeJS? NewsCred

NodeJSWhat’s this all about?

Saturday, September 17, 2011

What’s NodeJS? NewsCred

NodeJSEvented I/O for V8 JavaScript.

Saturday, September 17, 2011

What’s NodeJS? NewsCred

Goal“Provide an easy way to build scalable

network programs.”

Saturday, September 17, 2011

History NewsCred

The Evolution of the WebFrom static pages to real time data.

Saturday, September 17, 2011

Why NodeJS? NewsCred

The Age of Big DataExabytes (1018) of data stored per year

0

250

500

750

1000

20062007

20082009

2010

Saturday, September 17, 2011

Why NodeJS? NewsCred

The Fast Food AnalogySynchronous vs. Asynchronous

Saturday, September 17, 2011

Why NodeJS? NewsCred

The Apache SolutionSynchronous I/O

readFile();

Application

MySQL

User FileSystem

getTweets();

writeToDb();

Twitter API

Saturday, September 17, 2011

Why NodeJS? NewsCred

The Apache SolutionBlocking I/O

readFile();

Application

MySQL

User FileSystem

Waiting...

getTweets();

Waiting...

writeToDb();

Twitter API

Saturday, September 17, 2011

Why NodeJS? NewsCred

The NodeJS SolutionAsynchronous I/O

readFile();

Application

MySQL

User FileSystem

getTweets();

writeToDb();

Twitter API

Saturday, September 17, 2011

Why NodeJS? NewsCred

The NodeJS SolutionNon-blocking I/O

readFile();

Application

MySQL

User FileSystem

getTweets();

writeToDb();

Twitter API

Saturday, September 17, 2011

NodeJS Benefits NewsCred

• Fast• Built on top of Google’s V8 JavaScript engine.

• Scalable• Asynchronous, event-driven I/O model yields web scale.

• Programmable• JavaScript API and pluggable module architecture.

Saturday, September 17, 2011

• Serving APIs

• Serving real-time apps

• Serving web apps

• Streaming data

NodeJS Use Cases NewsCred

Saturday, September 17, 2011

NodeJS “Hello World!” NewsCred

var http = require('http');

http.createServer(function (request, response) { response.writeHead(200, {'Content-Type':

'text/plain'}); response.writeHead('Hello World!');}).listen(1337, '127.0.0.1');

Saturday, September 17, 2011

Who’s Using NodeJS? NewsCred

Saturday, September 17, 2011

Installing NodeJS NewsCred

• Installing on Unix

• Installing on Windows• Run http://nodejs.org/dist/v0.5.6/node.exe

Saturday, September 17, 2011

Installing npm NewsCred

• Node Package Manager (npm)

• One line install:• curl http://npmjs.org/install.sh | sudo sh

• Multi-line install:• Get the code from http://github.com/isaacs/npm

• Do what the REAMME says

Saturday, September 17, 2011

Part 2ExpressJS

NewsCred

Saturday, September 17, 2011

What’s ExpressJS? NewsCred

ExpressJSHigh-performance NodeJS

web framework.

Saturday, September 17, 2011

Why ExpressJS? NewsCred

• Full blown feature set• Routing

• View rendering/templating

• Sessions

• Good documentation• Lots of examples

• Many extensions

Saturday, September 17, 2011

Installing ExpressJS NewsCred

Saturday, September 17, 2011

Directory Structure NewsCred

Saturday, September 17, 2011

Configuration NewsCred

Saturday, September 17, 2011

Application Settings NewsCred

Saturday, September 17, 2011

Routing NewsCred

Saturday, September 17, 2011

View Rendering NewsCred

• Haml templates• Haml

• Jade

• Embedded JavaScript (EJS) templates

• Coffeekup templates• Uses CoffeeScript

• jQuery templates

Saturday, September 17, 2011

Views with Jade NewsCred

Saturday, September 17, 2011

Sessions NewsCred

• Currently cookie-based• Data store can be Redis, memory etc.

Saturday, September 17, 2011

Packages NewsCred

$ npm install -d # for installing dependancies

Saturday, September 17, 2011

Resources NewsCred

• NodeJS• http://nodejs.org

• http://github.com/dynamicguy/node-mongo-cms

• ExpressJS• http://expressjs.com

• Sencha Connect• http://github.com/senchalabs/connect/wiki

Saturday, September 17, 2011

Questions? NewsCred

Iraj Islamiraj@newscred.com, @irajislam

Nurul Ferdousnurul@newscred.com, @ferdous

Saturday, September 17, 2011

top related