Skip to content

Instantly share code, notes, and snippets.

@kazagkazag
Last active April 26, 2018 19:39
Show Gist options
  • Save kazagkazag/5dd355c708e82e3b40d787aeaec41d20 to your computer and use it in GitHub Desktop.
Save kazagkazag/5dd355c708e82e3b40d787aeaec41d20 to your computer and use it in GitHub Desktop.
const faker = require("faker");
server.get("/users/:id/articles", (request, response) => {
response.send(200, getArticlesForUser());
});
// you can create articles on the fly
// or prepare few articles upfront
// and just select them now
function getArticlesForUser() {
const howMany = faker.random.number({min: 1, max: 10});
const articles = [];
for(let i = 0; i < howMany; i++) {
articles.push({
title: faker.lorem.words(5),
content: faker.lorem.paragraphs(4),
createdAt: faker.date.recent()
});
}
return articles;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment