Devcast node.js e mongo db o casamento perfeito

2,899 views
2,746 views

Published on

Devcast feito 28/maio gravado em http://www.youtube.com/watch?v=-OpUd1Rov2c&lc=0GXp_SsI4D7w5p7ELDOUhqlspvrQAFF-EwBocHFEppk

Published in: Technology, Design
1 Comment
4 Likes
Statistics
Notes
  • Você pode pensar em publicar uns posts pra comunidade nossa http://nodebr.com/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,899
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Devcast node.js e mongo db o casamento perfeito

  1. 1. eJean Carlo Nascimento akaSUISSA
  2. 2. @osuissaabout.me/suissagithub.com/suissanosql.techinsider.com.brjavascript.techinsider.com.br
  3. 3. ● É um ambiente de execução para usar JavaScriptfora do navegador● Linha de comando + console interativo● Utiliza o engine de JavaScript Google V8● I/O orientada a eventos (modo assíncrono)
  4. 4. > function agora() {... var dt = Date().slice(16,24);... console.log(dt);... }undefined> agora();13:50:17undefined>
  5. 5. TerminologiaSQL RDBMSDATABASETABLEROWSQUERYINDEXPARTITIONMongoDBDATABASECOLLECTIONJSON DOCUMENTQUERYINDEXSHARD
  6. 6. Talk is cheap. Show me thecode.
  7. 7. Node.js - Hello Worldvar http = require(http);http.createServer(function (req, res) {res.writeHead(200, {Content-Type: text/plain});res.end(Hello Worldn);}).listen(1337, 127.0.0.1);console.log(Server running at http://127.0.0.1:1337/);
  8. 8. Node.js - Wassup Worldvar http = require(http);var fs = require(fs);var index = fs.readFileSync(index.html);http.createServer(function (req, res) {res.writeHead(200, {Content-Type: text/html});res.end(index);}).listen(3000);
  9. 9. Node.js - Rotas
  10. 10. expresshttp://expressjs.com/
  11. 11. Express● Routing robusto● Redirecionador para Helpers● Dynamic View Helpers● Integração View Template Engine● Content negotiation (RESTFul)● Application mounting● Focado em alta performance● Renderizador de Views● Suporte a Partials● Configuração baseado no ambiente do sistemaoperacional● Desenvolvido com a base no Middleware Connect
  12. 12. Express - Hello Worldvar express = require(express);var app = express.createServer();app.get(/, function(req, res){res.send(Hello World);});app.listen(3000);
  13. 13. jadehttp://jade-lang.com/
  14. 14. mongodb nativehttps://github.com/mongodb/node-mongodb-native
  15. 15. MongoDB Nativevar mongo = require(mongodb);var db = new mongo.Db(test, new mongo.Server(localhost,27017, {safe: true}), {});db.open(function(err, client){client.createCollection("docs", function(err, col) {client.collection("docs", function(err, col) {for (var i = 0; i < 10; i++) {col.insert({c:i}, function(){console.log("inserindo: " + i);});}});});});
  16. 16. mongoosehttps://github.com/LearnBoost/mongoose
  17. 17. Mongoosevar mongoose = require(mongoose),Schema = mongoose.Schema;var db = mongoose.connect(mongodb://localhost/db);var User = new Schema({first_name: String,last_name: String});var UserModel = mongoose.model(User, User);
  18. 18. Mongoosevar record = new UserModel();record.first_name = Jean;record.last_name = Nascimento;record.save(function (err) {UserModel.find({}, function(err, users) {for (var i=0, counter=users.length; i < counter; i++){var user = users[i];console.log( "User => _id: " + user._id + ",first_name: " + user.first_name + ", last_name: " + user.last_name );}});});

×