ferrara linux day 2011

15
Ferrara Linux Day 2011 The tools of NodeJs

Upload: gpadovani

Post on 15-May-2015

476 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Ferrara Linux Day 2011

Ferrara Linux Day 2011

The tools of NodeJs

Page 2: Ferrara Linux Day 2011

Evented I/O for V8 JavaScript.

Node's goal is to provide an easy way to build scalable network programs.

Node is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted.

HTTP is a first class protocol in Node. Node's HTTP library has grown out of the author's experiences developing and working with web servers.

Page 3: Ferrara Linux Day 2011

Event what???

Example:var http = require('http');

setInterval(function(){    console.log("Hello world");}, 2000);

var host = '127.0.0.1';var port = 12345;

http.createServer(function (req, res) {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello World\n');}).listen(port, host);console.log('Server running at http://' + host + ':' + port + '/');

Page 4: Ferrara Linux Day 2011

The first commit was:

"Autore: Ryan <[email protected]>  2009-02-16 01:02:00Revisione creata da: Ryan <[email protected]>  2009-02-16 01:02:00Figlio:  61890720c8a22a7f1577327b32a180a2d267d765 (add readme and initial code)Ramo: master, remotes/origin/autoconf, remotes/origin/back_to_waf, remotes/origin/debugger, remotes/origin/eventsource, remotes/origin/http_agent, remotes/origin/http_parser_refactor, remotes/origin/many_listener_warning, remotes/origin/master, remotes/origin/pointer_bindings, remotes/origin/reload, remotes/origin/v0.2, remotes/origin/v0.4, remotes/origin/writev, remotes/origin/writev2Segue: Precede: v0.0.1

    add dependencies"

the project is young!

Page 5: Ferrara Linux Day 2011

Very influenced from Ruby :-)

Page 6: Ferrara Linux Day 2011

How to install Node?

You can build https://github.com/joyent/node

Or use something like this:- Nave https://github.com/isaacs/nave- Nvm https://github.com/creationix/nvm- N https://github.com/visionmedia/nAll three are bash script that manage different versions on node in different dirs.

Page 7: Ferrara Linux Day 2011

In node there is only one way to manage packages: npm.

There was a big change in the first version, and now npm manages easily same packages with different versions in different projects.

The main actor is package.json defined in the CommonJs specifications.

Page 8: Ferrara Linux Day 2011

{  "author": "gpad",  "name": "nodelinuxday2011",  "description": "app example fo LinuxDay 2001",  "version": "0.0.1",  "homepage": "https://github.com/gpad/nodelinuxday2011",  "repository": {    "type": "git",    "url": "git://github.com/gpad/nodelinuxday2011.git"  },    [...]}

Page 9: Ferrara Linux Day 2011

{  [...]   "main": "./server.js",  "engines": {    "node": "*"  },  "dependencies": {    "formidable": "~1.0.6"  },  "devDependencies": {    "nodeunit": "~0.5.5",    "far": "~0.0.7"  }}

Page 10: Ferrara Linux Day 2011

package.json How it works?

see example ... Cloud9Ide

• Create a file with info e dependencies• Execute npm install

Install all the dependencies locally so don't conflicts with others in other projects.

What about devDependencies?

Page 11: Ferrara Linux Day 2011

package.json devDependencies How it works?

see example ... Cloud9Ide

npm install --production

install locally only the package necessary to deploy. The packages listed in devDependencies are not  installed ...

Cloud9Ide on version 1.8.7 works in different way, if you execute npm install install only "dependencies" if you execute npm install --dev also install the devDependencies

Page 12: Ferrara Linux Day 2011

What about testing? If you look this you will find a long list of modules for Testing / Spec Frameworks, some examples:

Cucumber — The official JavaScript implementation of the well-known BDD tool. Runs both on Node.js and browsers.expresso — TDD framework by the author of JSpecmaryjane — Mock object library inspired by Mockitonode-qunit — QUnit port for nodejs. Very simple API, async testing, good tested testing framework.nodeunit — Simple syntax, powerful tools. Based on the assert module. Available for node.js and the browser!

Page 13: Ferrara Linux Day 2011

So we are at the end, how to deploy?

If you use Cloud9ide is very simple (is in beta now I can't :-)) ..., you can deploy manually with Heroku tools in a very simple way.

There is a new platform called Nodejitsu with all the tools available on github.

Others use capistrano with this recipes 

Page 14: Ferrara Linux Day 2011

Other funny things??

• Jake - Similar to Rake• Cluster - Node.JS multi-core server manager with plugins support • Express - High performance, high class web development for

Node.js• Node-DbDeploy - A data migration tool inspired by dbdeploy

Page 15: Ferrara Linux Day 2011

Thank YOU !!!

Q & A