Backend Flashcards
What is a promise
An object that may have a value later on
A promise can have three possible states
- pending - initial state, neither fulfilled nor rejected
- fulfilled - meaning that the operation was completed successfully
- Rejected - meaning that the operation failed
async function getPaid(){
const houseOneWait = await houseOne()
const houseTwoWait = await houseTwo()
const houseThreeWait = await houseThree()
console.log(houseOneWait)
console.log(houseTwoWait)
console.log(houseThreeWait)
}
getPaid()
What is an API’s fetch
async function getACuteDogPhoto(){ const res = await fetch('https://dog.ceo/api/breeds/image/random') const data = await res.json() console.log(data) } getACuteDogPhoto()
Javascript, does it run in the browser?
Yes
JavaScript is running where in the browser
Sandboxed, it can’t get access to the browser in the computer
JS is a language that can only do what the hosting environment allows
What do servers do?
They serve up files
What do servers do?
They serve up files
What is Node.js
Node.js
The same stuff that lets you run JS in the browser can now be used to run JS on Servers, Desktops, and elsewhere
Just
HTTP & FS
const http = require('http') const fs = require('fs') http.createServer((req, res) => { fs.readFile('demofile.html', (err, data) => { res.writeHead(200, {'Content-Type': 'text/html'}) res.write(data) res.end() }) }).listen(8000)