Advanced Node and Express 11 - Tests should be done asynchronously
See original GitHub issueSo, 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:
- Created 5 years ago
- Reactions:22
- Comments:17 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
I want to thank @lucasMontenegro for the help!
Just to have it all in one place:
It took me a long time but it finally worked… good luck, all!