Created
June 19, 2017 14:48
-
-
Save Jonathancollinet/5de05e81a5c82d030878fe539b2d741e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"), | |
app = express(), | |
bodyParser = require('body-parser'), | |
users = require('../mocks/users.json').users, | |
notes = require('../mocks/notes.json').notes | |
app.use(function (req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
next(); | |
}) | |
.use(bodyParser.json()) | |
.use(express.static('../public')) | |
.get('/users', function (req, res) { | |
res.send(getNotesbyUser()) | |
}); | |
// map | |
// filter | |
// reduce | |
// forEach | |
// push // pop | |
// slice | |
// splice | |
function getNotesbyUser() { | |
return users.map((user) => { | |
user.notes = notes.filter((note) => note.userId === user._id) | |
return user | |
}) | |
} | |
getNotesbyUser() | |
let server = app.listen(9000, function () { | |
let host = server.address().address; | |
let port = server.address().port; | |
console.log("Adresse du serveur : http://localhost:9000", host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment