Retour d'expérience sur le développement d'une plateforme de jeux multi-joueurs et multi-écrans
app.get('/user/:id', function (req, res, next) {
console.log('ID:', req.params.id);
next();
}, function (req, res, next) {
res.send('User Info');
});
var socket = io('http://localhost');
socket.on('news', function (data) {
socket.emit('my other event', { my: 'data' });
});
NoSQL
stockage JSON sous forme de collection
CRUD
schéma
model
find, findById
save, remove, update
populate
var InvitationModel = mongoose.model("invitation", {
user: { type: mongoose.Schema.Types.ObjectId, ref: 'user' },
key: { type: String, required: true, unique: true, index: true },
createdAt: { type: Date, default: Date.now, expires: '24h'},
color: { type: String, enum: ["green", "orange", "red"], required: true },
data: { type: mongoose.Schema.Types.Mixed },
});
se branche sur express
collections, get, put, post, delete...
vérification champs obligatoires ou sur le type
requête de recherche
populate
middleware
GET http://localhost/api/v1/Customers/count
GET http://localhost/api/v1/Customers?name=value
GET http://localhost/api/v1/Invoices?populate=customer&select=customer.name
GET http://localhost/api/v1/Customers/:id
PUT http://localhost/api/v1/Customers/:id
POST http://localhost/api/v1/Customers/:id
DELETE http://localhost/api/v1/Customers/:id
MVVM
ES5 (getter, setter) donc incompatible avec IE8
two way data bindings
simple, léger et performant