Season-o2 Namaste Node.
js l6/69/2o24
Watefall Model(SDLC)
Requsements (PM +Deignes)
Desg énginoevt m
yDevelobment SÍE1,SDE2
L Testin SDET
bpelogmet
Maintainance.
Monolith Vs McOsetes
’Dev sþeed
Dev speed b slow in monoith be case a Lot
þeobhe woying on 3ame ebo.
*CodeRebo
MOholt has tuqe. sigle coodefepo -
Dtfecut to maintin
Scalabliy
Vey diffialt to gcale nonoit ahchitecture.
’0oymntdeþoment in monolith:
sihe
ca be a bro
-’ Tech stack
Kes ta'c ted ih hono utwie
’Jnta Cost
Comyl
As aty Comolexity lnoneeses k
’ Fault oleti
Testirg
uoeves has sebarate est caser
Tsting fn Munli'c iB bit easies.
’(Swnesp
ownehib in nmonollt
Ceutral
’ Maiutoinace
’Re wams
tbisode- 02| Featunes, HID,LLD B Plaming
ar.edu
OCreate nan accauntProductct veguincnent (done by rduet
manige)
Login
9 Update
Seed
SSond conne ction Kegues
6 See ou Matelhes
GSoe the eguet we tie Bet/reciend
6) update
Teck blannig
|BE
-React -No de JS
Menyons
Coce be comes
Aonwig,witng
gou blanning rs govdyow don't han to
actor et
LLD ( Low teel Bengn)
# DB Dexm
# HPD chesgn /Bocumert le APEs.
# DB
thst name
-last name
Smailld
þarsord
age, zencen
’Connectian Reguet
tosesld
Status =PENDING pen ding
arepted rjectal
#ArD Dedgn iRESTArZ3
qET. P0s7, PUT, PATCH ,0ELE Te
HTÍPthd PATCH
TOTrelaces u etye reso, ulule
of aresne.
pdates only batCRUS obeatny
POs T PATCH t file
Post /lo DELE TE tfle
7iotyjin
qET /oofile Post /endAevesttesene
POSTemeaccei
posT /ofile
GET eqets
GET 0nnf finy
ous Expros Seve
Shin ode o3|Creoing
4, 9.2
hajor mior batch
How to een tenhal in Vs ode? ctrlt n
npm intt ’ it wil initialiaze you pr/et
his will create a packege.jso
a eidex forgou bryle.
a likeand inde thes' a fk nom abbis
Packagejon istoder
CYeate a src
arja is te shating foid yas fbicaten
’ Here we will eni tt aliaze bh
abb.
Now, ne will wse ren-fs to create oui Seie
Serea Cam W'sten to alltide yeguest and hefond
Exþres is fas t cnopiniatd, mininalist web
’ow, tuo files will abbeee > o No de mo dales
I)
pckageleckyjon
that
.
Debondengy * Dahendeacy kany fackage
How to Aamalle request?
des. Bend C"Hellofm 3el er'),
his funchon (s called reguest handler.
wewat that ows e Sepond to patcales
te hen,
abb. use (7hello', (eg,res)=)5
eso sendCHollo,helio, hello);
Binstal nodomon at gobal levels
hodenEn (Becawe gou are tyyig to
whchegqules adrin þea)
"scnpts'"
"%tat':"node sr/opb.s
'dev :"nodemon Srabb.js
Crde
Const expres equine('expres) ;
COst apþ exes0
Tese Bend("Namaste Achay!"!
afbue("helo" (oeq, re) f helo):
eySerd Ca Helo hello,
3);
(e,re)>
Ofp wse ( est, es.send ("Hello from th seee);
Op. listcs(7777, ()=>
Cowsole. lo
3fo9/202+
Eþbode- 04 | Racting, and Requert Hondlots.
How to push yous cade on ge
gitinit
What f you delete node madule?
Dont anie, jat do
npm anstall.
As long as ae bakage jeon
ykon and
tackae Can reCreate
hode mo dues.
nodeo dles to
thats we neres psh
lo ill notto trak gome
Dh the n t
plae,
-gitigmodales
How to commit changos
t add.
?
Commut -n Ceated aa ebsSee
Create a e gthub thee tesnina cdet
e mode add
t
it branch -M ma
maiu.
omgin
g'should we busb backgetot
wüd cald in nocte han dless
i sendl" Hello")
ny ote statg fo 7) tmill Be
’ Now
Oveidden by thu's abot reguext han dler
we wn te 's rete fit:
1/ you outte is stavting from '), then
withhil he matche d to
ttis.
stauting
lihe helo will
Qire ane neelts f a ote g
Ofoend for Vaello!
code, a lot
Just by changg the orde st
8tat m matelung the route
he code will
Joom he top.
"O des o outes matter a lot!
HT TP Method
Get, bd bast, batcl, delete
How to handle deffaent method ,deffaaty
Ihstead
alth HTTPetho
Ari ca handle nay
Adu onced hngs about nuting
labc
this means bis eb tinal e hee
/ab?c
/abtc ’/abc , fabb c ,/abbbbc
/ob tcd abod, lobkandd, fobgafiacd
/albe)?e »abce, ac
/a(bc)tc ~ abtbc c /abcc
)
You Can also wite regex oveA hee
means /t dold contai
queit plans in oun Bo te han dles
How to get
ffo
conhole. loieuey,
/ser ?useid =lol
htt/ localhost
How to make outes dynanw'e?
htth/ lo callhost:/we f1
Console
ahhget Cuea/wand/:name/s paimod
Chole-lag(rgpams)
Spitode-os|| MdleweES an Erv Handley
One Rote can have mtible 0te lan dlers.
Code-l
Cowsole. loq(" Han dlina the rote userl];
(req, res) N)
Cooleslog("Han dling the ote lses
es sen 2nd Roßom
’
Respowe
- Coder2
how e will go to
next el handle.
cam also Create amay
Dte hondle.
You can thi's alio
Oþp. qetC?wsee", (r,res,nt)
(Owsole.
nextO;
tpget( euses", (>q, es, nuct) s
Des sen nd Rote Pa dla),
lhe hale middhewae b
apb se(adin', (rgrenuyolo this
Const tokon ='xyz';
If ClisAdndt)
ves.statusl44). send(einattenzad
nextO;
's to cte middle wnefolder.
Anothe
ahþ.
Emor Ham dling.
lwe try cateh
Put stiI| ome emr is wmhaudled,
Car hl ndle then by
Ot the (at
app.se(/',feet- (en, ecs,noa
neyKefatus (so). send(omethang
ent wmn
EpisodeO6|Database, Sehema & Modeb||
How to connet o abp to database?
Create a contg foldetigde Bre
Creae databos
dotbbase3
Const morgoose = rgue('mongooe)
Cot connetD8
wat mnan goose. coWhect(
Connected);
uemyr("ectabese
Cannot
be
tabhghe. coneio
es Cosole.
h8 log
); conretien
hon(
0sConnetPB(),
ex7res abb Cont
abok connectD&- cowt
egurCrerßres), expre cOmt
ConnedDE; module.entotr=
-uindat
Conret( mongoose Cwat
connetDB Conwt
('mmgoos), egire mongyoose nyt Co
databae;(3
eel. the -to
teu then ase, datab the Connet
to h*eFist
uelyang/dasabau'):
Creating the Schema
n sG create amodels Jolder.
HHt w e .credte a shema
COMt mongoose newqure (hofoox
Cona UseShena i mongo ose Schema (f
finstNome
tyfe stig
Jant Name i
3.
emaild -5
type:stng
þaswd;
3,
tyesfg
yheiNmbe
jendes
block. cAAch r
as lu A
eferat db the wyat
contaig itahd
cments. do
collechon aa sUsen
database s du TIin er
Cadedlr?
to's sarrel
/
th cwait
etu wdltunctia.
obj);cyCwses new
aehay23 pasword: :
d.cony enail
:ld
AlYha! fKNane:
tCAigmp pus ahp.
asedatab
fih ow add will e Now,
ou todata
=Gsesftod;
Usesj epont hodule-
orypomodel(
"Ussl
wb theMtet= Cont
oáel ongoose Creete wil we
/Now
nto the APP oViofa029
Side o Dring
(exres.jBon(): /t honse the faondatn
apb. use 7 trom reqiet objeel.
Now ge
new Uses lreg body ):
Const-ne wses s
hisde-o8| Date Soitigation 8 Sehama Validatiy
gda:
byestig,
valdate(vlue)
If( Dmale',"enal"otes'].inckudolvalels
noy EmGodes datais not sly
tow new
Ishis validate unctin wil only wook it
bame hew
nen obyec
7tou han to enebte i t r n gn bdater alto.
n the atek opi, jn the etiu sohe
uklidatos itre,
anait Uselretslocwod:
.findByBArdufelede(fid:useld'}, dats,
aYauatostoe
APL_level alidaton
ao. patch ((/se/: usetd, async (req, res)
Const we
use ld = Deg. banams 2. (uei ld,
Cowt dataz yeabodyo
yi
colstAuowE)_UPDA TeS= ['pho tovol', "about "gendel
agey "htVs
Cowt sUpdate Allowed Objectkeys(data)mno
=>ALOwEDUP DATES. includes(k
trow new Emr("Update nt allone;
the code, fow fou handle
Yht use cam pdeto only stletd itemg
Rate em.
Neter tust the uee data. apply all
the validatous to data.
s
1f(data?2. 8kilk.kongth o)cannotbe moe tha, o
thro new Error(Is kils
*ho
Atnaye hae backond validation an d an
Attakess, can 8teal PD
break DB.
’Jhis is caled 0cta Santisaton.
/oeCaac i5
y' Trut "Neve
bValidUt
os o lot aaddaadd Cau Stmil
Er'wald thnownew
(valueJs Emad validator
/s i5(
validatelvalue)
trmitre,
iniquetrue
eguired:true,
lonucaseitue.,
tye'stig
validator cOnst Schema
datos' ('vali epure
dtin. vai lerel APD
aidahn level De Schema
ortevela Tarye)
validatde
vaidator ihpm
validator nomnþm Callad
any extomal ofa heep take Can You
emaild? validate toHow
Eþisode o9|et Pasd
oo/ab24
An attac Keg can aend any maliious dataito
nene turt
is the enty boint
et sio ldd be
/ yaidation ef date
encypt tha baswond
/ creoate he hewitanc the maee
I Baure the mo dal to tHho database
t Now, ve will fustale beyt ibry for
Jer
Out
validateSpData(r
Const i fitNome, lastNane, emais Panwod
1/Sncypt t e þas word
Const basuodHosh cw athe bcypthah
anwod, lo);
cowole.logLpanwwmdHah);
o ney nstanco the Ues mode
Cost tUsee new Uges (
pos pamdH at
pars word : pas
art
'Send 'User Added
mfemation.
qive not hadd You
ext amyattaket
attacle
e'Invald slautd
Stotus es.
(e) Cateh
Passordljalid)7 ifis
pasimrd,
conpuel boypt owait ValsPaword
d
i= COut
is Evoy("
not EnaillD newthrow
DB) þrentin
nailD awat ue Const
body =re paswwrd fenmal
e, Cost
bpisode-1o | Athentication JwT oo kies
|o read the cooee, we need one ayioasd
none
npm libray that is coolcieprse.
nom Cookie-þarses.
headea payloud.natuie
nþm ij3onwrebtken
jutsveiy)
lcreate aJwT Token
agr( £-jd:-id oeven)
Cons t tolKans avaitjwt Send he tesbensk
dd
1/ A he token to coo kie amd
// oackto the wse
mes.cooKie ("to kew', to Ken
Const cookien = yeqycookie,
Cowst Stokeu = Cookies)
cOwt de - wat jwt veLity (tokeu/'okns}
const dy decteMenag
onyt we= wat Vs% find8yTd (-id);
thow newtrrvy( Ues dver not erst);
the auth middlewese
Creoting tWsesAH .eg res,next):
token from thereg, Curokes
I Read the
/ volidate tte toke
h fnd the wses
Const to Ken, , Tolcon
Const decoded Obj = await jwtietylto kan, dueg
const d}= de co del Ob;
CUst wel await U3es+ find
tiow hew Bnor ("Uses notfoun;
Jyea wel= Ulesi fust ataeh tu cwei tora,
nert0;
Catehlen )
yts.3 tatylgoo) send(enmree
JwT to Ken?
How
await jwt Wgn
expireslrn: "1d
1),
Coo kie
Yo cn ere
en espire
res. Cookielutoken', to ken,
Date(1octe. nonl+8*3000o),
exþires new
3);
Mongpose Schema Method
You Can d f ging
lload the methomethods.
JwT tokon t Schemna
* Make S e ahe not cing how func
inside ahow fun ti Hhus
Because
doesnt woh.
Const token aMrait we-getTwT():
modeli) welfs
uss schema. methods getTwT =asyuc fun ctio05
Co nst wie
Cost toKen= wait jwt. gn(&-id' we-b,
un tolen
modul extorts > mongoose mo dellPUsasnla)
You can 'aio lodd the b
asoT
coypt
boytt meths
wenShema. mthods. validate
asghe fm chio ChaswodaptyOe) $
Cont paxwordHat
Const sPaswordValid= cwait bcpt Compuel
þassnordat
etun ts Pasordvalid;
Valid =
CUnt 'slasmord (pasnprs
useheyalid Pasnord
Crat
into the APs and
ehisode 14].Divig Rotes
Apl contrat
# Dev n dea Ap
auth Bovtel
- posT /Jogi
PosT oyut
pro fileRouttka
GeT/ofilefuew
PATCH/rofle/edit
PATCH /brofile/þa% mord
) Conne ionAeguestfoenditeneted/use
utey N
- posT/reg est/
t/jerien/acoepted/'egest
(posT/eques
PosT/dqret ntw/reyetd/'eetly
-(Eleoyections
-Gerpejetsfeoeed
-çerfeed- Get goug hu frofiles cu wscu
ßlatfo
Stats i ing keetd, acreped, Yeyeted
t we will wse exþres Routet to bhandle
hose inany
Tast do the log'oal sebaatn
Epwda 2| Logi'cal DB quey
Conbound Dnder o3hefass
Gui databese
Ne will do in deing to cpiv ze
Compound Indea last Nane:1);
erSchema.index({ fstName'1 ,
Wnitig APls
Proces PosT
Thaugt
Youy -he
databae.
o t caser &chene
We wiln Crete a seion betne
dnd conne chonkeuest Schema.
Const Conne ctfar Raqet Sdoma = mongooe Schena(
tyfe: mongoose"shra. ypas.Cyeid,
eurtd: tue,
wenlodea-get /oi/reues ty/ teceied; wseytds
cont loggedhu/a
await Conecalqete
Contt connetionRaaests =
to Vsetd t logedlaei.-ld,
. bolate( "fomlUseldj fL"fstNaWlast
" a e LastNom
Cse not the data.
’Make SUie