Day 48

in code •  7 years ago 

March 2nd, 2018

Hello! At the ES6 course by Wes Bos I learned about the Async Await. If you execute something synchronously you wait for the task to be done, before you continue. But if you do it asynchronously you start the task, but you move on to the next thing immediately. We need to pause JS for a moment, and the continue it. Async await is built on promises.We use the 'async' in front of the function, and 'await' in front of the promise.

 async function go() {
      console.log('start');
      const res = await breathe(1000);

How to catch an error if there is no .then()

High order function: a function that takes in a function as an argument and returns a new function.
Used when handling all the errors in a similar way.

At the Web Development Bootcamp by Colt Steele I learned about post requests. I am finally starting to see how the internet works.

 app.post("/addfriend", function(req, res){
        var newFriend = req.body.newfriend;
        friends.push(newFriend);
        res.redirect("/friends");
});

  app.get("/friends", function(req, res) {
       res.render("friends", {friends:friends});
   });

You can add new “friends” to the friends page, and it stores it there. The {friends:...} is the object that stores the new info.

You need to install body-parser.

        npm install body-parser --save

        app.use(bodyParser.urlencoded({extended: true}));

Body parser is needed because that is how the new input in the form will be stored in the app.

<form action="/addfriends" method="POST">
     <input type="text" name="newfriend" placeholder="name">
     <button>I made a new thing!</button>
 </form>

The method, action, and name are needed to connect the form with the app.js

Cheers!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!