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 Node.js Basics (2014) Building a Command Line Application Perfecting: Getting Multiple Profiles

Placid Rodrigues
Placid Rodrigues
12,630 Points

User data with more badges and points showed before user data with less badges and points. How?

On 03:43 of this video, we see that, in app.js, data of chalkers, joykesten2 and davemcfarland was requested sequentially from the url. And davemcfarland had more badges and points than chalkers. Still, when the file is executed in the console, davemcfarland's data showed before chalker's data.

As Andrew Chalkley mentioned in a previous lesson, data of chalkers should show before that of davemcfarland due to non-blocking nature of Node.js

Then why is this happenning?

1 Answer

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hey Placid Rodrigues!

A number of reasons can determine wether something with seemingly more data could be returned quicker than something with less data. The important note is to understand that they can comeback in any order, or more accurately when each one is "ready".

Maybe Dave's profile or part of their profile is cached on the web server. Maybe Dave's profile has less variety in badges awarded in different topic areas so the database might not have to work as hard to find all the achievement information. Maybe the TCP/IP packets for the request for my profile took a long route across the Atlantic and back...who knows?

But the most important take away is that things can happen out of sync with asynchronous programming.