Giter Site home page Giter Site logo

drinks's Introduction

VIRTUAL DRINKS

This week, I created a virtual bartending website, where you can access a list of drinks and add your own to the list. I used the Npm package drinks. https://www.npmjs.com/package/drinks. You can get a list of drinks by clicking on the button "Get Drinks". You can also add to the list of drinks by entering your favorite drink into the input box, which you will see added to the list at the end.

Website

PROCESS

Overview

This week was a lot learning in terms of learning Node.js and how it interacts with the client side. I wanted to understand the types of HTTP requests : GET, PUT, PUSH, DELETE, so focused more on those concepts rather than the design. I worked through the backend guide and workbook.

DEVELOPMENT

I didn't realize the proper structure of a JSON file until I ran into issues using my file to push to my array. Within the JSON were multiple sets of data with name of drink, min and max. I wanted to access the "name" of the drinks and ignore the "min" and "max", however, it was difficult for me to access the name itself since there was no higher "drinks" object. Next time doing this I would pick a JSON file that has objects or format in myself to include an object.

After understanding the JSON file, I wanted to display all the drink names on screen through the button click. That required connecting the server side and the client side, a relationship that I was quite confused by. I met with Cassie to help me explain their separation and how they communicated was through the Fetch API. I would use the async/await to create the Fetch API.

First, to test that I could get all the data I did a console.log on the button click. Next, I used innerHTML to display the items on screen. Originally, I tried to to drinks.innerHTML, but that was throwing an error since that was a JSON file. Working with a classmate, Aditya, he recommended creating a separate element to append my text to and changed to text.innerHTML to display the items in a list.

I decided to add another level and have the user add a drink to the list. When I worked through the workbook, I tried to adopt the POST method, and tried to push to my array, but this is where structurally the JSON interfered with me executing my code. To add a drink, I created a function :

function addDrink(drink) {
	const cocktails = getDrink(); 
	cocktails.drinks.push(drink); 
	fs.writeFileSync(path.join(__dirname, "./data/drinks.json"), JSON.stringify(drinks));)

}

I spent lots of time fiddling with my addDrink function and consulted a classmate, Jason, who told me there were no object called "drinks" within the json file. So I edited my code instead of saying cocktails.drinks.push(drink), it said cocktails.push(drink).

function addDrink(drink) {
    const cocktails = getDrink(); 
    cocktails.push(drink);
    fs.writeFileSync(path.join(__dirname, "./data/drinks.json"), JSON.stringify(cocktails)); 
    return cocktails;
  }

I added another event listener to my input field and Jason helped me with structuring the POST method on the client side code of the input field.

GENERAL THOUGHTS / QUESTIONS

I think this week was particularly challenging to understand how node.js works. I also think that working with certain JSONs and APIs is something still to get used to. Overall, jumping into backend and parsing through JSON data and how it relates to the client side was a bit difficult to understand conceptual wise. Hypothetically, the different HTTP requests make sense, but the execution takes practice. It's nice that there is a consistent format with the HTTP requests in app.get("url", req, res) {}. I think the confusing part was the specific syntax used for each request. Also, the specific formats of JSONs

  1. For example, for POST, the request was "req.body.variable". What is body and is it only used for POST?
  2. I'm a bit confused as to what this line is doing - "fs.writeFileSync(path.join(__dirname, "./data/drinks.json"), JSON.stringify(drinks));)

NEXT STEPS

Eventually, I want a user to randomly select a drink upon a GET request, adding a drink/item on a POST request, replacing an item with PUT request and deleting something on a DELETE request as if they were their own virutal bartender.

ACKNOWLEDGEMENTS

  • Cassie Tarakajian
  • Aditya Jain
  • Jason Tse
  • Ashwita Palekar

drinks's People

Contributors

abbylee321 avatar

Watchers

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.