PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

https://github.com/glenjamin/node-intro-challenge
Markdown | 63 lines | 43 code | 20 blank | 0 comment | 0 complexity | 8244bcb3e7b7de64987b8e95e1a3cf2d MD5 | raw file
  1. # NodeJS What, Why & How Challenge
  2. This short challenge introduces you to handling control flow while making
  3. asynchronous HTTP requests to major search engines.
  4. Be careful which files you open, as all the solutions are already present
  5. in this repository.
  6. ## 0. Setup
  7. The file `setup.js` contains a short bit of bootstrap which will time your
  8. script and also provides the search URLs.
  9. > node setup
  10. { google: 'http://google.com/search?q=',
  11. bing: 'http://www.bing.com/search?q=',
  12. yahoo: 'http://search.yahoo.com/search?p=',
  13. ask: 'http://www.ask.com/web?q=',
  14. duck: 'http://duckduckgo.com/?q=' }
  15. Start with `challenge.js`, which requires the URL list and takes the search
  16. terms from the command line.
  17. Useful Links:
  18. http://nodejs.org/docs/latest/api/http.html
  19. http://nodejs.org/docs/latest/api/url.html
  20. ## 1. Parallel HTTP requests
  21. Use node's stdlib HTTP client to make a request to each of the search engines
  22. and then print the first 100 characters of the response to the console.
  23. Solution: `challenge-parallel.js`
  24. ## 2. Serial HTTP requests
  25. To demonstrate the complexities of control flow with async, now modify your
  26. previous solution to make the requests one-at-a-time.
  27. You can try and do this by hand, or use the async library.
  28. Solutions: `challenge-series.js` `challenge-series-async.js`
  29. ## 3. Parallel requests with summary
  30. Firing stuff off in parallel is easy enough, but knowing when asynchronous
  31. tasks have completed is less so. Combine the results of all of the queries
  32. into a single object keyed by engine name that contains the time taken to
  33. process the request and the data.
  34. {
  35. google: {time: 1.34, data: '<html>...' },
  36. yahoo: {time: 1.34, data: '<html>...' },
  37. bing: {time: 1.34, data: '<html>...' },
  38. ...
  39. }
  40. Again, you can try and do this by hand, or use the async library.
  41. Solutions: `challenge-summary.js` `challenge-summary-async.js`
  42. For bonus points pull the URL to the first result out of the data and include
  43. that in the returned object.