Skip to main content

NodeJs Basic Exercise

Goals

In this exercise, we will ask you to understand leverage all the basic skills you got from the previous lesson. We will focus mostly on Data Manipulation skill with High Order Functions, Spread Operator, etc.

You only to run your NodeJs program using Webstorm Run or command line interface.

Requirements

  1. Use this Fake JSON API: https://jsonplaceholder.typicode.com/
  2. Get data from all users from API above. You will get a list of 10 users.
  3. Get all the posts and comments from the API. Map the data with the users array. The data format should be like this:
const users = [
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"comments": [
{
"id": 5,
"postId": 1,
"name": "vero eaque aliquid doloribus et culpa",
"body": "harum non quasi et ratione\ntempore iure ex voluptates in ratione\nharum architecto fugit inventore cupiditate\nvoluptates magni quo et"
},
// More comments
],
"posts": [
{
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
// More posts
]
}
]
  1. Filter only users with more than 3 comments.
  2. Reformat the data with the count of comments and posts
const users = [
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"commentsCount": 12,
"postsCount": 34
},
//more users
]
  1. Who is the user with the most comments/posts?
  2. Sort the list of users by the postsCount value descending?
  3. Get the post with ID of 1 via API request, at the same time get comments for post ID of 1 via another API request. Merge the post data with format:
const post = {
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"comments": [
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
// More comments
]
}

Once you have finished all the requirements, please contact your instructor for evaluation and reviews.

Help

If you need any help clarifying these requirements, see this video: