Devcast node.js e mongo db o casamento perfeito

  • 2,268 views
Uploaded on

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

More in: Technology , Design
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Você pode pensar em publicar uns posts pra comunidade nossa http://nodebr.com/
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
2,268
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
1
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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