question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Advanced Node and Express 11 - Tests should be done asynchronously

See original GitHub issue

So, I thought I should report something I found. My app* was being accepted/rejected at random by this challenge. Apparently the tests are not waiting for the server to respond and that causes them to fail (since they depend on each other).

After adding some delays to my responses the probability to pass the test increased a lot (if a timeout doesn’t occur).

// Enable to pass the challenge called "Advanced Node and Express - 
// Registration of New Users"
if (process.env.ENABLE_DELAYS) app.use((req, res, next) => {
  switch (req.method) {
    case 'GET':
      switch (req.url) {
        case '/logout': return setTimeout(() => next(), 500);
        case '/profile': return setTimeout(() => next(), 700);
        default: next();
      }
    break;
    case 'POST':
      switch (req.url) {
        case '/login': return setTimeout(() => next(), 900);
        default: next();
      }
    break;
    default: next();
  }
});

* Here is a link for making a new app on Glitch. (You only have to complete the .env file.)

I also had issues with some of the following challenges.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:22
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
smartITNinjacommented, Dec 8, 2018

Yes, I passed this test today using @lucasMontenegro tip.

But, additionally do this:

1.- Clear you database 2.- Update your server.js file (eg: append a new blank line) to restart the application 3.- Run the test

Important: In my case, if you don’t update your server.js file before running the test then you won’t be able to pass it.

fcc_advanced_node_express_registration_of_new_users_1

1reaction
h15200commented, Sep 5, 2019

I want to thank @lucasMontenegro for the help!

Just to have it all in one place:

  1. Use Lucas’s helpful glitch link
  2. set the env ENABLE_DELAYS=true along with your other settings
  3. In my case I had to change the profile.pug line 11 to: h1.border.center Profile Home FCC Advanced Node and Express
  4. Clear your database
  5. Restart the server on server.js (just hit return)
  6. Run the test and pray!

It took me a long time but it finally worked… good luck, all!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top Node.js Interview Questions and Answers in 2023 - Edureka
Below is the list of the tasks which must be done asynchronously using the event loop: I/O operations; Heavy computation; Anything requiring ...
Read more >
Top 50+ Node.js Interview Questions and Answers for 2023
Node.js is perfect for data-intensive applications as it uses an asynchronous, event-driven model. You can use I/O intensive web ...
Read more >
Asynchronous Patterns in Node.js - GeeksforGeeks
The async functions can contain more than one await expression. This await keyword is used to wait for the promise either to be...
Read more >
Top 50 Node.js Interview Questions & Answers for 2022
Synchronous functions are mainly used for I/O operations. They are instantaneous in providing a response to the data movement in the server and ......
Read more >
19+ Advanced Node.js Interview Questions For Senior ...
Q8: What are the Timing features of Node.js? · setTimeout/clearTimeout - can be used to schedule code execution after a designated amount of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found