Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Asynchronous Code in Express Asynchronous Code in Express Refactor Using Async/Await

index.pug For Each User in Users declaration and express route

Hi there

I have a question regarding how the declaration in the views folder for the index file is being used.

I see that the index.pug file has a "user" in singular that I cannot relate directly to the users const variable declaration in app.js file and with the users.users Json data attribute from the JSON file.

body ul each user in users li(class="user") i(class="material-icons") account_box h3 #{user.name} p #{user.username} p #{user.bio}

Thanks in advance for any feedback given to this server.

1 Answer

James Crosslin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 Points

Sorry nobody got around to answering this question earlier, but this portion of the index.pug file is what allows you to reference the user variable:

      each user in users 
        li(class="user")
          i(class="material-icons") account_box
          h3 #{user.name}
          p #{user.username}
          p #{user.bio}
      each user in users 

In this snippet from the file, each is a forEach method. It is cycling over each object in users and performing the action of creating a list item for each of them. Hope this helped!