node.js, uma breve introdução
DESCRIPTION
Uma breve introdução a plataforma Node.js.TRANSCRIPT
![Page 1: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/1.jpg)
node.jsIntrodução
![Page 2: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/2.jpg)
node.js?- Ryan Dahl- Criado em 2009- Escrito em C++ e Javascript - Multiplataforma (Linux, Windows e Mac)- Foco em alta escalabilidade e em tempo real- Versão atual: 0.10.26 / Fev 18, 2014- Open Source mantido pela Joyment
https://github.com/joyent/node
![Page 3: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/3.jpg)
O que é?- Plataforma para utlizar Javascript fora do navegador. (Focada em servidores)
- Escrita sobre interpretador V8 do GoogleOu seja, essa plataforma é escrita com códigos C++ e Javascript
- Baseada em eventos
- I/O não bloqueante
![Page 4: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/4.jpg)
Servidores “Comuns”
![Page 5: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/5.jpg)
![Page 6: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/6.jpg)
![Page 7: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/7.jpg)
![Page 8: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/8.jpg)
![Page 9: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/9.jpg)
![Page 10: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/10.jpg)
Servidores que usam Node.js
![Page 11: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/11.jpg)
![Page 12: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/12.jpg)
![Page 13: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/13.jpg)
![Page 14: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/14.jpg)
![Page 15: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/15.jpg)
![Page 16: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/16.jpg)
Quer dizer que...- Você tem o poder do Javascript para criar aplicações orientadas a eventos e assíncronas em qualquer máquina.
- Sua premissa é facilitar a construção de aplicações de rede (servidores web, etc.) sem bloqueio de leitura e escrita.
- Ao instalar o node, o mesmo já vem com uma biblioteca inicial muito poderosa. http://nodejs.org/api
- Comunidade de desenvolvedores extremamente entusiasmada.
![Page 17: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/17.jpg)
What?var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
>> node hello.jsServer running at http://127.0.0.1:1337/'
![Page 18: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/18.jpg)
Por que usar?- Aplicações com dados em tempo real- Aplicações com muitas, muitas requisições ao mesmo tempo- Aplicações com colaboração entre muitos usuários- Chats- Envios de dados (upload de arquivos)- Jogos- Servidor para diferentes protocolos ao mesmo tempo
- APIs (Sim, web apis, bitches)
![Page 19: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/19.jpg)
Por que NÃO usar?
- Aplicações que utilizam muito processamento (redimensionamento de imagens, renderização de vídeos, cálculos matemáticos pesados, etc.)
- Simples páginas HTML
- Aplicações baseadas em conteúdo, CRUDs, com muitas regras de negócio
- Aplicações dependentes de bancos de dados relacionais
![Page 20: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/20.jpg)
Empresas que utilizam
Mais em: http://nodejs.org/industry/ e: http://bit.ly/1kBolIL
![Page 21: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/21.jpg)
Então, node.js é...- Plataforma para desenvolver aplicações com Javascript- Com foco em para alta escalabilidade para alta concorrência - Performance com altas cargas de acesso- Multiplataforma- Comunidade de desenvolvedores super ativa- Ainda imatura- Não soluciona todos os problemas do mundo
![Page 22: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/22.jpg)
FimTchau, comercial
![Page 23: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/23.jpg)
node.jsjs fora do seu navegador
![Page 24: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/24.jpg)
The good stuff- Javascript- Fácil de instalar (hoje é)- Multiplataforma- V8- Pacotes, muitos pacotes- Event Loop - Conduz os desenvolvedores ao mindset de “Evented/Async I/O”
![Page 25: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/25.jpg)
Event Loop- Single-Thread que escuta por todas requisições ao servidor
- Ao receber req. que precisam realizar operações bloqueantes (acesso a disco, computação pesada, etc), criar uma tarefa async para o SO e guarda um callback para esse tarefa
- Continua recebendo outras requições, até receber a resposta da tarefa enviado o SO, então executa o callback, espera até estar livre e executa esta respota
- Abstrai toda implementação de gerenciamento de threads, consumo de memória, etc
![Page 26: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/26.jpg)
Multi-threaded HTTP server
![Page 27: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/27.jpg)
Node.js Server
![Page 28: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/28.jpg)
Multi-threaded concurrency Single threaded concurrency
Multi vs Single threaded concurrency
![Page 29: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/29.jpg)
Synchronous I/O Asynchronous I/O
Sync vs Async I/O
![Page 30: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/30.jpg)
Alguns problemas- É Javascript
Algumas bizarrices (www.wtfjs.com)Facilidade em não seguir padrõesNão é orientado a objetos
- Por default, exceções matam o processo- Vazamentos de memória difíceis de encontrar- Ainda é beta (~v 0.10.26)- Single thread trava em códigos de alto processamento- Falta de maturidade para utilizar bancos de dados relacionais
![Page 31: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/31.jpg)
“I got 99 problems but a callback aint one”
Callback HELL
![Page 32: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/32.jpg)
npm - node packeges manager- É o gerenciador de pacotes oficial do node.
- Nele já são mais de 61k pacotes escritos pela comunidade de desenvolvedores.
- Instalado junto ao node, que é uma dependência (óbvia) para o uso do npm.
- Utilizado através da linha de comando, possuí uma API poderosa para a instalação e busca de pacotes. https://www.npmjs.org/doc/
![Page 33: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/33.jpg)
Utilizando o npm: Instalando pacote
![Page 34: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/34.jpg)
Utilizando o npm: Baixando pacotesNa pasta root do projeto, criar o arquivo packages.json. {
'name': 'mini-chat' ,
version: '0.0.1',
description: 'Chat app.',
engines: {
'node': '>= 0.6.x',
npm: '>= 1.1.x'
},
dependencies: {
'express': '>= 2.x.x',
now: '>= 0.x.x'
},
}
![Page 35: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/35.jpg)
Utilizando o npm
![Page 36: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/36.jpg)
ExemplosSHOW ME THE CODE
https://github.com/ruanmyv/node-examples
![Page 37: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/37.jpg)
Hello worldhello-app
![Page 38: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/38.jpg)
Numbersnumbers-app
![Page 39: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/39.jpg)
Chatchat-app
![Page 40: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/40.jpg)
Expressexpress-app
![Page 41: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/41.jpg)
Fim²
![Page 42: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/42.jpg)
Show me the links!!http://nodebr.com/
http://howtonode.org/
http://nodejs.org/
https://github.com/joyent/node
http://www.nodebeginner.org/
http://callbackhell.com/
Why The Hell Would I Use Node.js? A Case-by-Case Introduction
Node Tools for VS - Youtube
Introducing node.js Tools for Visual Studio
Node.js para iniciantes
O que é npm do nodejs
O que exatamente é o Node.js?
What are the disadvantages of using Node.js?
Node.js for Beginners
Java EE threads v/s Node.js – which is better for concurrent data processing operations
Beginner’s Guide To Node.Js (Server-Side JavaScript)
Node.js para leigos
![Page 43: Node.js, Uma breve introdução](https://reader031.vdocuments.pub/reader031/viewer/2022020105/55625371d8b42aa52d8b5223/html5/thumbnails/43.jpg)
Slideshare - Node.js: serious business
Slideshare - Node.js campus party brasil 2011
Future-proofing Your Apps: Cloud Foundry and Node.js
7 minimal Node.js webframeworks
Concurrent programming for scalable web architetures
You’ll never believe how LinkedIn built its new iPad app (exclusive) [Linkedin]
Blazing fast node.js: 10 performance tips from LinkedIn Mobile [Linkedin]
Here's why you should be happy that Microsoft is embracing Node.js [Microsoft]
Yahoo! Announces Cocktails � Shaken, Not Stirred [Yahoo]
Why Walmart is using Node.js [Walmart]
Fluent 2013: Bill Scott, "Clash of the Titans: Releasing the Kraken | NodeJS @paypal" [Paypal]
Show me the links!!