• Save
Devcast   node.js e mongo db o casamento perfeito
Upcoming SlideShare
Loading in...5
×
 

Devcast node.js e mongo db o casamento perfeito

on

  • 2,871 views

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

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

Statistics

Views

Total Views
2,871
Views on SlideShare
2,871
Embed Views
0

Actions

Likes
4
Downloads
0
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Você pode pensar em publicar uns posts pra comunidade nossa http://nodebr.com/
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Devcast   node.js e mongo db o casamento perfeito Devcast node.js e mongo db o casamento perfeito Presentation Transcript

  • eJean Carlo Nascimento akaSUISSA
  • @osuissaabout.me/suissagithub.com/suissanosql.techinsider.com.brjavascript.techinsider.com.br
  • ● É 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)
  • > function agora() {... var dt = Date().slice(16,24);... console.log(dt);... }undefined> agora();13:50:17undefined>
  • TerminologiaSQL RDBMSDATABASETABLEROWSQUERYINDEXPARTITIONMongoDBDATABASECOLLECTIONJSON DOCUMENTQUERYINDEXSHARD
  • Talk is cheap. Show me thecode.
  • 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/);
  • 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);
  • Node.js - Rotas
  • expresshttp://expressjs.com/
  • 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
  • Express - Hello Worldvar express = require(express);var app = express.createServer();app.get(/, function(req, res){res.send(Hello World);});app.listen(3000);
  • jadehttp://jade-lang.com/
  • mongodb nativehttps://github.com/mongodb/node-mongodb-native
  • 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);});}});});});
  • mongoosehttps://github.com/LearnBoost/mongoose
  • 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);
  • 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 );}});});