Code Monkey home page Code Monkey logo

node-intro-challenge's Introduction

NodeJS What, Why & How Challenge

This short challenge introduces you to handling control flow while making asynchronous HTTP requests to major search engines.

Be careful which files you open, as all the solutions are already present in this repository.

0. Setup

The file setup.js contains a short bit of bootstrap which will time your script and also provides the search URLs.

> node setup
{ google: 'http://google.com/search?q=',
  bing: 'http://www.bing.com/search?q=',
  yahoo: 'http://search.yahoo.com/search?p=',
  ask: 'http://www.ask.com/web?q=',
  duck: 'http://duckduckgo.com/?q=' }

Start with challenge.js, which requires the URL list and takes the search terms from the command line.

Useful Links: http://nodejs.org/docs/latest/api/http.html http://nodejs.org/docs/latest/api/url.html

1. Parallel HTTP requests

Use node's stdlib HTTP client to make a request to each of the search engines and then print the first 100 characters of the response to the console.

Solution: challenge-parallel.js

2. Serial HTTP requests

To demonstrate the complexities of control flow with async, now modify your previous solution to make the requests one-at-a-time.

You can try and do this by hand, or use the async library.

Solutions: challenge-series.js challenge-series-async.js

3. Parallel requests with summary

Firing stuff off in parallel is easy enough, but knowing when asynchronous tasks have completed is less so. Combine the results of all of the queries into a single object keyed by engine name that contains the time taken to process the request and the data.

{
    google: {time: 1.34, data: '<html>...' },
    yahoo: {time: 1.34, data: '<html>...' },
    bing: {time: 1.34, data: '<html>...' },
    ...
}

Again, you can try and do this by hand, or use the async library.

Solutions: challenge-summary.js challenge-summary-async.js

For bonus points pull the URL to the first result out of the data and include that in the returned object.

node-intro-challenge's People

Contributors

sky-glenjamin avatar

Stargazers

Glen Mailer avatar

Watchers

Glen Mailer avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.