Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Not an issue, but something interesting #33

Open
Joshfindit opened this issue Feb 28, 2021 · 0 comments
Open

Not an issue, but something interesting #33

Joshfindit opened this issue Feb 28, 2021 · 0 comments

Comments

@Joshfindit
Copy link
Contributor

https://www.digitalocean.com/community/tutorials/how-to-write-asynchronous-code-in-node-js

They use ghibliapi as the teaching tool

callbackMovies.js

const request = require('request');

request('https://ghibliapi.herokuapp.com/films', (error, response, body) => {
    if (error) {
        console.error(`Could not send request to API: ${error.message}`);
        return;
    }

    if (response.statusCode != 200) {
        console.error(`Expected status code 200 but received ${response.statusCode}.`);
        return;
    }

    console.log('Processing our list of movies');
    movies = JSON.parse(body);
    movies.forEach(movie => {
        console.log(`${movie['title']}, ${movie['release_date']}`);
    });
});
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant