SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
NodeJS, CS y ExpressJS
Como programar solo en JavaScript
y no morir en el intento.
“es una plataforma construida sobre el
Javascript runtime de Chrome, con el fin de
construir aplicaciones de red rápidas y
escalables.”
Esencialmente
I/O
- http
- net(tcp)
- udp
- fs
- dns
- etc...
Muchos modulos
HTTP Server de ejemplo
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello Worldn');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
- single threaded
- todo I/O es no bloqueante
- muchos callbacks
- no bloquear el reactor
Event Loop
Require()
//mate.js
var mate = {
cuadrado: function(x) {
return x * x
},
cubo: function(x) {
return x * cuadrado(x);
}
};
module.exports = math;
//otro.js
var express = require('express')
var mate = require('./mate.js')
mate.cuadrado(2);
mate.cubo(2);
- Instalar modulos:
Node Package Manager
npm install express
- Manejar dependencias (definidas en package.json):
npm install
gem install sinatra
bundle install
- Congelar dependencias:
npm shrinkwrap Gemfile.lock
package.json
{
"name": "TicTacToeNODE",
"version": "1.0.0",
"description": "",
"main": "app.js",
"engines": {
"node": "~1.4.28"
},
"dependencies": {
"body-parser": "^1.10.1",
"express": "^4.10.7",
"express-session": "^1.10.0",
"mongodb": "^1.4.28"
},
"devDependencies": {
"coffee-script": "^1.8.0"
},
"author": "",
"license": "ISC"
}
Dato Curioso
rubyGems: 94,343 gems (desde 2003).
npm: 116,873 packages (desde 20011).
- lenguaje que compila a javascript.
- es directamente compatible con librerías.
javascript (y vice-versa).
- sintaxis bonita. :D
- tiene su propia consola para node.
numero = 15
numeros = [1, 2, 3]
nombres = [
'Santi'
'Miguel'
'Mati'
]
cuadrado = (x) ->
x * x
mate =
cuadrado: (x) ->
x * x
cubo: (x) ->
x * cuadrado x
if numero > 10
console.log "Un numero: #{numero}"
console.log("Un numero: #{numero}") if numero > 10
var numero = 15;
var numeros = [1, 2, 3];
var nombres = ['Santi',
'Miguel',
'Mati'];
var cuadrado = function(x) {
return x * x
};
var mate = {
cuadrado: function(x) {
return x * x
},
cubo: function(x) {
return x * cuadrado(x);
}
};
if (numero > 10) {
console.log("Un numero: " + numero);
};
Javascript Coffeescript
Clases
class WinConditionRow
constructor: (rowNumber) ->
@rowNumber = rowNumber
hasWon: (board, player) ->
board[@rowNumber].every (cell) ->
cell == player
winCondition = new WinConditionRow(1)
winCondition.hasWon(board, player)
class Persona
constructor: (nombre, apellido) ->
@nombre = nombre
@apellido = apellido
obtenerNombreCompleto: ->
"#{@nombre} #{@apellido}"
class Doctor extends Persona
obtenerNombreCompleto: ->
"Dr. #{super()}"
Listas y bucles
num for num in [1..10]
game.getId() for game in games when game.isFinished()
for game in games
do (game) ->
game.play player, 0, 0
console.log game.getBoard()
ExpressJS
- framework web similar a Sinatra.
- super minimalista y modular.
express = require 'express'
app = express()
app.get '/', (req, res) ->
res.send 'Hello World!'
app.listen 3000
get '/match_ups' do
currentPlayerId = session[:player_id]
{player_id: currentPlayerId,
match_ups_pending_id: getPendingMatchUpsFor(currentPlayerId),
match_ups_finished_id: getFinishedMatchUpsFor(currentPlayerId)
}.to_json
end
app.get '/match_ups', (req, res) ->
currentPlayerId = req.session.playerId
resJSON =
player_id: currentPlayerId
match_ups_pending_id: pendingMatchUpIdsBy currentPlayerId
match_ups_finished_id: finishedMatchUpIdsBy currentPlayerId
res.send resJSON
express
Sinatra
session = require 'express-session'
bodyParser = require 'body-parser'
app.use express.static("#{__dirname}/public")
app.use bodyParser.json()
app.use session(cookieConfig)
app.post '/play_match_up/:match_up_id', (req, res) ->
gameId = parseInt req.params.match_up_id
i = parseInt req.body.i
j = parseInt req.body.j
game = getGameById(gameId)
game.play req.session.playerId, i, j
res.sendStatus 200
Conclusiones

Mais conteúdo relacionado

Mais procurados

GLX, DRI, and i965
GLX, DRI, and i965GLX, DRI, and i965
GLX, DRI, and i965
Chia-I Wu
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 

Mais procurados (20)

Travis CI+Dockerで複数バージョンの単体テスト
Travis CI+Dockerで複数バージョンの単体テストTravis CI+Dockerで複数バージョンの単体テスト
Travis CI+Dockerで複数バージョンの単体テスト
 
Introduction of ES2015
Introduction of ES2015Introduction of ES2015
Introduction of ES2015
 
...Lag
...Lag...Lag
...Lag
 
JSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael GreifenederJSUG - Scala Lightning Talk by Michael Greifeneder
JSUG - Scala Lightning Talk by Michael Greifeneder
 
Arp
ArpArp
Arp
 
Mysql5.1 character set testing
Mysql5.1 character set testingMysql5.1 character set testing
Mysql5.1 character set testing
 
GLX, DRI, and i965
GLX, DRI, and i965GLX, DRI, and i965
GLX, DRI, and i965
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへ
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 
Orm
OrmOrm
Orm
 
SdE 2: Le langage Python, Allocation de memoire
SdE 2: Le langage Python, Allocation de memoireSdE 2: Le langage Python, Allocation de memoire
SdE 2: Le langage Python, Allocation de memoire
 
Mysql handle socket
Mysql handle socketMysql handle socket
Mysql handle socket
 
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
 
Richard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptuRichard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptu
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
The Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single ThreadedThe Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single Threaded
 
Consuming Web Services with Swift and Rx
Consuming Web Services with Swift and RxConsuming Web Services with Swift and Rx
Consuming Web Services with Swift and Rx
 
Snake.c
Snake.cSnake.c
Snake.c
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 

Destaque

San Francisco PHP Meetup Presentation on Zend Framework
San Francisco PHP Meetup Presentation on Zend FrameworkSan Francisco PHP Meetup Presentation on Zend Framework
San Francisco PHP Meetup Presentation on Zend Framework
zend
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
expressjs-cleancontroller-160427080619
expressjs-cleancontroller-160427080619expressjs-cleancontroller-160427080619
expressjs-cleancontroller-160427080619
Roman Sachenko
 
Application of nodejs in epsilon mobile
Application of nodejs in epsilon mobileApplication of nodejs in epsilon mobile
Application of nodejs in epsilon mobile
Tony Vo
 

Destaque (20)

San Francisco PHP Meetup Presentation on Zend Framework
San Francisco PHP Meetup Presentation on Zend FrameworkSan Francisco PHP Meetup Presentation on Zend Framework
San Francisco PHP Meetup Presentation on Zend Framework
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
expressjs-cleancontroller-160427080619
expressjs-cleancontroller-160427080619expressjs-cleancontroller-160427080619
expressjs-cleancontroller-160427080619
 
Devdays Seattle jQuery Intro for Developers
Devdays Seattle jQuery Intro for DevelopersDevdays Seattle jQuery Intro for Developers
Devdays Seattle jQuery Intro for Developers
 
SITCON2014 LT 快倒的座位表
SITCON2014 LT 快倒的座位表SITCON2014 LT 快倒的座位表
SITCON2014 LT 快倒的座位表
 
Nature
NatureNature
Nature
 
Intro to Laravel 4 : By Chris Moore
Intro to Laravel 4 : By Chris Moore Intro to Laravel 4 : By Chris Moore
Intro to Laravel 4 : By Chris Moore
 
Cooking with jQuery
Cooking with jQueryCooking with jQuery
Cooking with jQuery
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend Framework
 
PHPBootcamp - Zend Framework
PHPBootcamp - Zend FrameworkPHPBootcamp - Zend Framework
PHPBootcamp - Zend Framework
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Express yourself
Express yourselfExpress yourself
Express yourself
 
Application of nodejs in epsilon mobile
Application of nodejs in epsilon mobileApplication of nodejs in epsilon mobile
Application of nodejs in epsilon mobile
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
Beginning Jquery In Drupal Theming
Beginning Jquery In Drupal ThemingBeginning Jquery In Drupal Theming
Beginning Jquery In Drupal Theming
 
Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
 
Laravel tips
Laravel tipsLaravel tips
Laravel tips
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework Development
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 

Semelhante a Node lt

JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
Edward Capriolo
 

Semelhante a Node lt (20)

JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
An introduction-to-windows-powershell-1193007253563204-3
An introduction-to-windows-powershell-1193007253563204-3An introduction-to-windows-powershell-1193007253563204-3
An introduction-to-windows-powershell-1193007253563204-3
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
All you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loop
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Devcast node.js e mongo db o casamento perfeito
Devcast   node.js e mongo db o casamento perfeitoDevcast   node.js e mongo db o casamento perfeito
Devcast node.js e mongo db o casamento perfeito
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Node lt

  • 1. NodeJS, CS y ExpressJS Como programar solo en JavaScript y no morir en el intento.
  • 2. “es una plataforma construida sobre el Javascript runtime de Chrome, con el fin de construir aplicaciones de red rápidas y escalables.”
  • 4. - http - net(tcp) - udp - fs - dns - etc... Muchos modulos
  • 5. HTTP Server de ejemplo var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello Worldn'); }).listen(8124); console.log('Server running at http://127.0.0.1:8124/');
  • 6. - single threaded - todo I/O es no bloqueante - muchos callbacks - no bloquear el reactor Event Loop
  • 7. Require() //mate.js var mate = { cuadrado: function(x) { return x * x }, cubo: function(x) { return x * cuadrado(x); } }; module.exports = math; //otro.js var express = require('express') var mate = require('./mate.js') mate.cuadrado(2); mate.cubo(2);
  • 8. - Instalar modulos: Node Package Manager npm install express - Manejar dependencias (definidas en package.json): npm install gem install sinatra bundle install - Congelar dependencias: npm shrinkwrap Gemfile.lock
  • 9. package.json { "name": "TicTacToeNODE", "version": "1.0.0", "description": "", "main": "app.js", "engines": { "node": "~1.4.28" }, "dependencies": { "body-parser": "^1.10.1", "express": "^4.10.7", "express-session": "^1.10.0", "mongodb": "^1.4.28" }, "devDependencies": { "coffee-script": "^1.8.0" }, "author": "", "license": "ISC" }
  • 10. Dato Curioso rubyGems: 94,343 gems (desde 2003). npm: 116,873 packages (desde 20011).
  • 11. - lenguaje que compila a javascript. - es directamente compatible con librerías. javascript (y vice-versa). - sintaxis bonita. :D - tiene su propia consola para node.
  • 12. numero = 15 numeros = [1, 2, 3] nombres = [ 'Santi' 'Miguel' 'Mati' ] cuadrado = (x) -> x * x mate = cuadrado: (x) -> x * x cubo: (x) -> x * cuadrado x if numero > 10 console.log "Un numero: #{numero}" console.log("Un numero: #{numero}") if numero > 10 var numero = 15; var numeros = [1, 2, 3]; var nombres = ['Santi', 'Miguel', 'Mati']; var cuadrado = function(x) { return x * x }; var mate = { cuadrado: function(x) { return x * x }, cubo: function(x) { return x * cuadrado(x); } }; if (numero > 10) { console.log("Un numero: " + numero); }; Javascript Coffeescript
  • 13. Clases class WinConditionRow constructor: (rowNumber) -> @rowNumber = rowNumber hasWon: (board, player) -> board[@rowNumber].every (cell) -> cell == player winCondition = new WinConditionRow(1) winCondition.hasWon(board, player) class Persona constructor: (nombre, apellido) -> @nombre = nombre @apellido = apellido obtenerNombreCompleto: -> "#{@nombre} #{@apellido}" class Doctor extends Persona obtenerNombreCompleto: -> "Dr. #{super()}"
  • 14. Listas y bucles num for num in [1..10] game.getId() for game in games when game.isFinished() for game in games do (game) -> game.play player, 0, 0 console.log game.getBoard()
  • 15. ExpressJS - framework web similar a Sinatra. - super minimalista y modular. express = require 'express' app = express() app.get '/', (req, res) -> res.send 'Hello World!' app.listen 3000
  • 16. get '/match_ups' do currentPlayerId = session[:player_id] {player_id: currentPlayerId, match_ups_pending_id: getPendingMatchUpsFor(currentPlayerId), match_ups_finished_id: getFinishedMatchUpsFor(currentPlayerId) }.to_json end app.get '/match_ups', (req, res) -> currentPlayerId = req.session.playerId resJSON = player_id: currentPlayerId match_ups_pending_id: pendingMatchUpIdsBy currentPlayerId match_ups_finished_id: finishedMatchUpIdsBy currentPlayerId res.send resJSON express Sinatra
  • 17. session = require 'express-session' bodyParser = require 'body-parser' app.use express.static("#{__dirname}/public") app.use bodyParser.json() app.use session(cookieConfig) app.post '/play_match_up/:match_up_id', (req, res) -> gameId = parseInt req.params.match_up_id i = parseInt req.body.i j = parseInt req.body.j game = getGameById(gameId) game.play req.session.playerId, i, j res.sendStatus 200