This document is a cheat sheet for developing back-end applications using Node.js and Express, focusing on asynchronous I/O with callbacks. It explains the use of promises, the axios package for handling HTTP requests, and the concept of callback functions, including the 'Pyramid of Doom' problem associated with nested callbacks. Key code examples illustrate how to implement these concepts effectively.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
6 views2 pages
Node 6
This document is a cheat sheet for developing back-end applications using Node.js and Express, focusing on asynchronous I/O with callbacks. It explains the use of promises, the axios package for handling HTTP requests, and the concept of callback functions, including the 'Pyramid of Doom' problem associated with nested callbacks. Key code examples illustrate how to implement these concepts effectively.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0108120285, 08:00 aboutlank
Developing Back-End Apps with [Link] and Express
Module 2 Cheat Sheet: Asynchronous 1/0 with Callback Program
PackageMethod Description Code Example
rR ee) setae
Syne function asynceanlO)
fons. tog(atlarg"):
feonst result = avait [Link](orl)s
ones lng(ressie- dot)
}
eynecalio;
‘We can await promises as ong as they ate
Asyneawait being called inside styncbronovs functions,
7rinetion(res) and fnetion(err) are the aronyess ealibck Functions
[Link]) €
‘otsolerlosteess
daeseenceurtdonter®)
Calfacks ae method that are passed » seen)
prams Tey are ved withthe
metodo which hey ar passed ab
ramet, cndonlly or
conta, We ue clack witha
promis to procs he esponte or eer
ets get (ur) then
jeseene
‘A objec thats returned by some
‘methods, representing eventual completion
Promise ‘elie, The ede ecatinoes to oe
‘without geting blocked unl the promis is
Fulled or an exception throw
ee promt = require promt-ayne 0
Ie fewrenusretre ye
fenst nethesil = uw Prondse({resave,ceject)=>(
Tet ltrs arog (nwtUo the hae oF the He 795
resolvetdata);
» Saeenterr|
er stesyne(FStenae, (encadings“utf8", fg:"e"))s
sine,
de
Promised when he proce he tees
Snwfibefincion wench teste | Senta
Fromieww cae | Hferemote URL aces LO operon file | (ne) cea gna)
sedge ;
coiectonp Teds an vet ane ae Tape pions Swcinsson) f
Framework calls when an event occurs et butter =
[Link]('aaa", fanerden(eniak) (
ee
[Link]¢‘ant, fanction()
onsale LogtoutFer),
senso
about blank 1(014082028, 08:00
aoutblank
Callback HelvThe
Pyramid of Doom
[Newtod callbacks stacked blow one
nother and waiting fr the previous
callback This eeates a pyramid stuctare
‘hat affects the readability and
‘maintainability af the code
cones akecane = pentstep => (
Toyangredients(Fanctior(cbopringList) {
“onsinetnpresientstinsl, nbeet,Foncion(Snareatents){
akecateCoven, pny function(aateer)
TecorsteCicing, function(este) {
rewestep(ea)s,
yf
yi
ye
»
»®
Axios Request
‘The axios package handles HTTP requests
anid eur a promise object.
conse axis = reguive( anton") defeules
‘onat conmeceTOOR=(3)-9¢
Tonet negeaion-get (uri)
ensue togireait
Fea then(raso=>(
foncaleriog(Fuifiilee"):
fensote: log(rsa. det);
»
daten(erron{
fens. tog Regectee"):
a
,
oon ouRt('vslse-ur3")
connect Tout “Ivaliuey')
@®) Skills Network
about blank
2