-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
19 lines (15 loc) · 1.04 KB
/
app.js
File metadata and controls
19 lines (15 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const express = require("express"); //lets us use express
const server = express(); //creates the server for express
const axios = require('axios'); //uses axios
server.set("view engine", "ejs"); //use expressjs
let cocktailResponse; //variable to hold the response when we call for a random cocktail
let drinkIndex; //variable to hold the actual index of the drink to display thedata associated with the drink later
server.get("/",(eRequest, eResponse) => //i use eRequest and eResponse here just to easily be reminded that these are the terms for express
{
axios.get("https://www.thecocktaildb.com/api/json/v1/1/random.php/small") //get a random drink with axios, small so the image isnt too big
.then((cocktailData) => //used to hold the data obtained from the api
{
drinkIndex = cocktailData.data.drinks[0]; //get the actual index of the drink we got
eResponse.render("index", {drinkIndex}); //actually display the drink and that drinks data on the main page
})});
server.listen(3000, () => console.log("Server is live")); //start the server