24
Quinta-feira, 22 de Agosto de 13

Node.js and express

Embed Size (px)

DESCRIPTION

Short introduction about Node.js and Express

Citation preview

Page 1: Node.js and express

Quinta-feira, 22 de Agosto de 13

Page 2: Node.js and express

AgendaNode.js

About

Benefits

Installing

NPM

Express

About

Installing Express & Generate an app

Jade & Stylus

Quinta-feira, 22 de Agosto de 13

Page 3: Node.js and express

about me

15 years programming experience

Software Developer and MSSQL DBA @ Com-UT/Sedimap

using Node.js about 3 years

Quinta-feira, 22 de Agosto de 13

Page 4: Node.js and express

NODE.JS

Quinta-feira, 22 de Agosto de 13

Page 5: Node.js and express

Node - About

Node.js is a platform to build fast and scalable network applications

we know this can be very painful and hard in some languages

Quinta-feira, 22 de Agosto de 13

Page 6: Node.js and express

Node - AboutIt is built on GoogleV8 JavaScript engine, the libuv platform abstraction layer and a core library, which is itself primarily written in JavaScript.

perhaps the best and faster JavaScript engine...

Quinta-feira, 22 de Agosto de 13

Page 7: Node.js and express

Node - About

event-driven

defined as an application technique in which the application has a main loop

non-blocking I/Ois a form of I/O processing that permits other processing to continue before the last transmission has finished

Quinta-feira, 22 de Agosto de 13

Page 8: Node.js and express

Quinta-feira, 22 de Agosto de 13

Page 9: Node.js and express

Node - BenefitsSmall Core

Multi-Platform

implements some CommonJS specifications

Easy to use, easy to start

JavaScript on server, JavaScript on client

Single thread simplifies concurrency

Package Module (NPM)

Community

Great Modules (like underscore, async, express, request, etc...)

Rapidly changing, e.g., updating in shortly time

Quinta-feira, 22 de Agosto de 13

Page 10: Node.js and express

Installing Node

Go to http://nodejs.org/

Windons and Mac OS X click on “install”

Linux, using package manager

Gentoo, Ubuntu, Fedora, etc...

Quinta-feira, 22 de Agosto de 13

Page 11: Node.js and express

Installing Node(Cont.)Install from source code

wget http://nodejs.org/dist/v0.10.x/node-v0.10.x.tar.gz

tar xzf node-v0.10x.tar.gz

./configure

make

make test

make install

node --version

Quinta-feira, 22 de Agosto de 13

Page 12: Node.js and express

NPMHow to find a module

npm search express

https://npmjs.org/

Some attentions you need to take before install a module

were updated relatively recently

have github repositories linked

have READMEs with good documentation

have at least some number of people instaling them every week

are liberally licensed (feel free to use)

Quinta-feira, 22 de Agosto de 13

Page 13: Node.js and express

Installing a module

Global Mode

will install in /usr/local/lib/node_modules

is more suited for modules that should always be available

Local Mode

NPM default mode

“your application path”/node_modules

is ideal for installing the modules your applications depends

don’t affect others applications that you have installed

use always this mode is more safe

Quinta-feira, 22 de Agosto de 13

Page 14: Node.js and express

Let’s Playwith a

TCP Server Chat

Quinta-feira, 22 de Agosto de 13

Page 15: Node.js and express

EXPRESS

Quinta-feira, 22 de Agosto de 13

Page 16: Node.js and express

About

is a minimal and flexible web application framework

provide a robust set of features for buildingsingle, multi-page and hybrid web applications

is based on the Connect middleware

and implements MVC

Quinta-feira, 22 de Agosto de 13

Page 17: Node.js and express

Installing & Generate an app

sudo npm install -g express

express --sessions --css stylus myapp

cd myapp & npm install

node app

Quinta-feira, 22 de Agosto de 13

Page 18: Node.js and express

Express - app

package.json (some app settings)

app.js (launch app)

public/*

routes/*

views/*

Quinta-feira, 22 de Agosto de 13

Page 19: Node.js and express

Jade

is a high performance template engine

implemented with JavaScript for node

Quinta-feira, 22 de Agosto de 13

Page 20: Node.js and express

HTML

JADE

Quinta-feira, 22 de Agosto de 13

Page 21: Node.js and express

Stylus

robust, feature-rich CSS language built for node

providing an efficient, dynamic and expressive way to generate CSS

Quinta-feira, 22 de Agosto de 13

Page 22: Node.js and express

CSS

Stylus

Quinta-feira, 22 de Agosto de 13

Page 23: Node.js and express

Some Resources

Node.JS

http://nodeguide.com/ (Felix Geisendörfer)

https://github.com/maxogden/art-of-node (Max Ogden)

http://nodetuts.com(Pedro Teixeira)

Express

http://expressjs.com/

http://www.senchalabs.org/connect/

http://learnboost.github.io/stylus/

http://jade-lang.com/

Quinta-feira, 22 de Agosto de 13

Page 24: Node.js and express

Quinta-feira, 22 de Agosto de 13