Giter Site home page Giter Site logo

async-javascript's Introduction

Asynchronous JavaScript

This project is a demonstration of asynchronous JavaScript on the server (using NodeJS) and in the browser.

Requirements

Get the Code

Download the code for this project by using git clone:

git clone https://github.com/Learn-by-doing/async-javascript.git

Install Node Modules

Like any node project, you will need to run download and install the required node modules for the project to run. Use the following command:

npm install

Once that has finished, you can run the program like this:

npm start

You should see the following if everything is OK:

Server started and listening at localhost:3000

Try the demo

Open your browser to localhost:3000 and enter a search query. After a short while you should see search results in the page. Here is what is happening:

  • The browser:
    • intercepts the search form submission.
    • sends a request to your local web server.
    • waits for a response from the local web server.
  • The local web server:
    • receives the request.
    • sends a request to the Shodan web API.
    • waits for the response from Shodan.
    • receives the response from Shodan.
    • sends a response to the browser.
  • The browser receives the response from the local web server.

Each of these requests/responses are asynchronous and allow other operations to happen during the waiting time.

Going further

The JavaScript code running in the browser can be found in the index.html file. There are four different examples of asynchronous JavaScript in the browser-side code:

  • A simple timeout loop
  • A timeout with a delay of 0 seconds
  • An AJAX request
  • Use of the async.util function from the async.js utility library.

Read the source and comments for further explanation.

async-javascript's People

Contributors

chill117 avatar

Watchers

 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.