Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Javascript: Primeiros Passos
Search
Dmitry Rocha
July 18, 2015
Technology
91
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Javascript: Primeiros Passos
Meus primeiros passos em Javascript no backend.
Dmitry Rocha
July 18, 2015
More Decks by Dmitry Rocha
See All by Dmitry Rocha
Crystal Lang - Introduction
dmitryrck
0
140
Docker (for developers)
dmitryrck
0
220
Introdução a testes automatizados
dmitryrck
0
56
Introdução a Linguagem Crystal
dmitryrck
0
310
Docker
dmitryrck
0
75
Scoola Talk
dmitryrck
0
70
Testes, testes everywhere
dmitryrck
0
57
Saltos no Vim - GURUPI
dmitryrck
0
55
Other Decks in Technology
See All in Technology
Compose 新機能総まとめ / What's New in Jetpack Compose
yanzm
0
160
証券システムを10年Scalaで作り続けるということ - 関数型まつり2026
krrrr38
3
830
ヘルスケア領域における AI 活用と その安全性担保のための取り組み (Leveraging AI in Healthcare and Our Efforts to Ensure Its Safety) - Google I/O Extended Tokyo 2026, July 11, 2026
zettaittenani
0
260
AI時代のエンジニアキャリアについて今一度考える
sakamoto_582
2
1.5k
キャリアの中で本を作る / Making a Book During Your Career
ak1210
0
130
Genie Ontologyは銀の弾丸かを考える / Is Genie Ontology a Silver Bullet?
nttcom
0
220
DMM.com 購入改善推進チーム におけるCodeRabbitを用いた レビューフロー改善の一例
ysknsid25
2
590
地域 SRE コミュニティ最前線 / SRE NEXT 2026 Discussion Night Track C
muziyoshiz
0
210
勉強会企画をアプリで構造化してみた 〜そこで見えた、AIとの付き合い方〜 / I've structured a study group plan using an app.
pauli
0
340
Control Planeで育てるBtoB SaaSの認証基盤 - SRE NEXT 2026
pokohide
1
2.2k
貴方はどのエンジニアリングを磨くのか
hatyibei
0
110
Zoom2Youtube.Claude
kawaguti
PRO
3
490
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
WENDY [Excerpt]
tessaabrams
11
38k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
210
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
180
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
Typedesign – Prime Four
hannesfritz
42
3.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Transcript
Javascript: Primeiros Passos Dmitry Rocha GURUPI, PUG-PI, THC, … July
18, 2015 1 / 25
Mas primeiro: Javascript no backend E Primeiros passos 2 /
25
Meu projeto, minhas regras 1. Liberdade de escolha da tecnologia;
2. Esta parte do projeto: banco de dados somente leitura; 3. Servidor e banco de dados legado; 3 / 25
Eu não decidi fazer em javascript. 4 / 25
Eu fui… …marotamente tentando acessar o banco de dados via
js… 5 / 25
Eu fui… …marotamente tentando acessar o banco de dados via
js… …”vou renderizar uma notíciazinha aqui”… 6 / 25
Eu fui… …marotamente tentando acessar o banco de dados via
js… …”vou renderizar uma notíciazinha aqui”… …PUTZ: FIZ A PORRA TODA EM JS. 7 / 25
Javascript Básico + Testes 8 / 25
Javascript Básico + Testes $ npm init 9 / 25
Javascript Básico + Testes $ npm init $ npm install
mocha --save-dev 10 / 25
Javascript Básico + Testes $ npm init $ npm install
mocha --save-dev $ npm install expect.js --save-dev 11 / 25
Live coding ;) 12 / 25
Banco de Dados sequelizejs.com 13 / 25
Banco de Dados $ npm install sequelize 14 / 25
Live coding? Not today 1 var DataTypes = require('sequelize'); 2
var sequelize = new DataTypes('database', 'username', 3 'password', { 4 logging: false, port: 'port', host: 'host' 5 }); 6 var db = {}; 7 8 db.DataTypes = DataTypes; 9 db.sequelize = sequelize; 10 11 var news = sequelize['import'](__dirname + '/news'); 12 var section = sequelize['import'](__dirname + '/section'); 13 db.news = news; 14 db.section = section; 15 db.news.belongsTo(db.section, { foreignKey: 'secao_id' }); 16 17 module.exports = db; 15 / 25
Banco de Dados: ”model” 1 module.exports = function(sequelize, DataTypes) {
2 return sequelize.define('news', { 3 title: DataTypes.STRING, 4 content: DataTypes.TEXT, 5 status: DataTypes.INTEGER, 6 date: DataTypes.DATE, 7 'secao_id': DataTypes.STRING 8 }, { 9 tableName: 'noticias', 10 underscored: true, 11 timestamps: false, 12 scopes: { 13 'feed': { 14 where: { status: 1 }, 15 order: [ ['id', 'desc'] ], 16 limit: 20 17 }, 18 } 19 }); 20 }; 16 / 25
Banco de Dados: teste 1 process.env.NODE_ENV = 'test'; 2 var
expect = require('expect.js'); 3 describe('News', function(){ 4 before(function() { 5 this.db = require('../../models'); 6 7 this.news = { 8 title: 'Letters from Germany', slug: 'letters-from-germany', data: new Date() 9 }; 10 }); 11 12 beforeEach(function() { return this.db.news.destroy({ truncate: true }); }); 13 14 describe('create', function() { 15 it('should be persisted', function(done) { 16 return this.db.news.create(this.news).then(function(news) { 17 expect(news.isNewRecord).to.equal(false); 18 19 return done(); 20 }); 21 }); 22 23 it('has title', function(done) { 24 return this.db.news.create(this.news).then(function(news) { 25 expect(news.titulo).to.equal('Letters from Germany'); 26 27 return done(); 28 }); 29 }); 30 // … 31 }); 32 }); 17 / 25
Servidor Web expressjs.com 18 / 25
Servidor Web $ npm install express 19 / 25
Servidor Web: exemplo básico 1 var express = require('express'); 2
var app = express(); 3 4 app.get('/', function (req, res) { 5 res.send('Hello World!'); 6 }); 7 8 var server = app.listen(3000, function () { 9 var host = server.address().address; 10 var port = server.address().port; 11 12 console.log('Example app listening at http://%s:%s', host, port); 13 }); 20 / 25
Servidor Web: Gerador $ npm install express-generator -g 21 /
25
Servidor Web: Gerador $ npm install express-generator -g $ express
myapp --ejs 22 / 25
Servidor Web: Gerador $ npm install express-generator -g $ express
myapp --ejs Live showing, exemplo do gerador. 23 / 25
Mais informações no meu blog. Fiz duas postagens sobre uso
do sequelize com jasmine 1 e sequelize com mocha 2. 1Jasmine e Sequelize: Uma introdução - http://dmitryrck.github.io/jasmine-sequelize/ 2Mocha, expect.js e Sequelize: Uma introdução - http://dmitryrck.github.io/mocha-sequelize/ 24 / 25
25 / 25