0 ratings0% found this document useful (0 votes) 19 views59 pagesAbhinodejs
React:
1. Component
2. JSX
3. Props
4. State
5. Hooks
6. useEffect
7. useState
8. Context API
9. Virtual DOM
10. Lifecycle
11. React Router
12. Redux
13. Functional Component
14. Class Component
15. Rendering
16. Prop Drilling
17. Fragment
18. Reconciliation
19. Babel
20. Webpack
Node.js:
21. Event Loop
22. NPM
23. Express.js
24. Middleware
25. REST API
26. HTTP Module
27. Callback
28. Async/Await
29. Promise
30. File System (fs)
31.
Copyright
© © All Rights Reserved
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
a
&
didi,
t KHonal xb Herve 2 Uke
different from WadWoral web dewves be tt
4
Apache oy Nain because they work on muh threaded
‘ et
Mode]. As they Crake anes thread fr each User YeMes
which Gn be hea fot jhe Sysle ,
e MARTYCO what ts Node js 9
Nee environerent
Cross platforra Yun
Ans: | Node js &5 open eBoutee, p
: deer Ale.
allosiny — USex do wn javascnph On the
Ty is built ow Seosle’s VB enyine pach #5 alse cae J
Chrome fo vin javases ph.
2 Nosg}s operates on a sinte threaded, everr driven rede).
“Tis weans that fastead 2) creaking a ne Yrvend doy each
Mest | Node js hrandies multiple Sreques aypelerancucly,
ak once. ‘by Processing asygnchrmously woithiout: Batting
jos one do fnish before. stavhiny another.
> Nodejs 98 different from Wadonal tacbderer he frke
Apache or Ninh becuse they work on mubh threaded
Mode). fis they Create anes thread fer each User ve quest
which Gn be hearty for the Syskem ,Sittin.
>)
CG) that an
cd ave the key Frakes of wedejs 9
Sol! @. Cy
2 ress ~Platfom 9, /
means ,jhalows users BP pulet
apblicabons thal can yun on various oper
eharys 2 Ge.
Syseres wither syn feant
b. Single df
gle hreuded mioctel L
Eh is dinjle preaded , bet nedejs an
handle. muliple Conechons concern,
Arough ifs event lop makes ib
scalabre and Capalte OF Man eghYJ
mute request.
le JS
Ce Hitn Performan ce.
gait on VE exine , whieh cov!
do neve machine @de
event dvi ver) 5
non -bleckiny mode) which
makes it effecient ant Suileble
de fondle asynchronous farckinas
Opevedtons.
uses
d. Event -dyiven Drchitechore
% Node:}s
with yd ecosyster of Ii byes and
€: NPM > pode cores
ny rh easy
Package wai lore Ayrayh WPM mel
fp add funchonotity and reuse code.G) Whal is the purpose of fackase Js file fn a rede js byoject
fot Th;
a TS & Cuca) Greponent of the Node-js project. Skis sesporsible
fos maney; he
GO Manns applicakon — deperdencies, “OY Agurcdion ard meta-data
wohich mnakes easey to develop , mmintain and share the project
puroses ae:-
bre of the
O Project info > gk holds base dehile about projet ke fr name,
a Version, deccviphion jaudier and license.
® Veperdenies 3 TH hiss the Uthrates and tools your prjec#
needs to west furchon peferiy.
@ Serbs > ou can uyile Shottads for common fag that su
Can un easly caith Simple lomnand .
€x. You can make “NPe she 4 > "shut.
@ Nersions 4 Te hel?s 0 keep track 4 which versions sf
———
the Mibrary Your project ases,
© ifonge tithe > tt shovss Ponder ohich Deense your projet &,
ah ts Pop for Jeg reasons.
a Packs - Lock json > Wensures that Wame dependenty versions
x installed each tine Someone sels opthe
Project, providiy a Consistent development
@Wirvonment. |Y
@ What event Loch an No de js 9
Sol! -F
So) ae to
© even Gropp 8 ce mecheanisen — thih allows pode js 1
beyjorm non-blocking T{a obevadions. fh rneans it aloes
nate js 40 fanclle asyach ynous operafoas ,
— uh on}
While one operahon is berg processed Ltke dreading a file
ov en ene
raking @ nehoork- request , Node js Can Cony
+ lle
re handle other tasks withedk waihing Jor Ihe fost one fofoih.
How dees t wore 9
pocceme )
Q Call suck —? When a program Slarls , junctions ave pushed onto a
cali stack - this Stack exeades furchon in lask in,
frorow (tf) manne’.
(2) slo Operdons —> when an Tlo Operahon occurs Ci fee
reading a file or Gerdiay a nehoork rest ,
ELIS removed from the Slack and handeled
in backprund jallowiny
executiny offer Cede -
nedejs 7 Conknue>
>
;
® Ever’ Queue s- Once the To Operation Fs Completed
‘ts caltback Auvbion 4s b
event Queue.
bleced fr an
@) Eveot ‘loop = = oatne event loeb Conkintia sty
Steck ¢5 abr
Cheeks “te call
+ Cohen it is | the event loops
takes fhe GS) fanchon from the event queue
ard pushes #4 onto the ceall Jack dey cxeahon ,
scam ble
Leagine you want da read & file and then make
an APL Cali.
> gow Snthiate the pe read ofeadton , bl {fou don't wath for th
pris ;
> hile the fle %5 bein Re yead, you proceed fo mate the
APL call.
— When \oo%h Operations fh
nish, dhe Aespechve Callback furckons
are f
wshed Onto the cal Stack pr exeuhon,
This way Nede}s can handle mulople
Aequesss ficeaty éS) > what ae module fy ne
ade 7's 9 Hows clo You ‘inp
exhort them 2
ot} and
=" Modules fn rede js Me weusghle block o lode “Hap
contains hinconelity thal can be Used
cis A od n Sed across iP forts of aff
> Th help to organige Goode. Snhy manageable pieces ranks
1
“it easiey fo cote and moinkin,
> Each module Can Contain i ovn variables , Junchons and
Classes -
—> HMedules help Organije Code and promote reuse -
Exporiny a medule,- [Oiig mode SB J.
=
Cons myfurction = Ors
Consle- dog (“¥eile");
Ue,
module. exports.
[ustag exports ‘
Const myfurchon = C) > §
Consele fog (: Helio")
ip
ports. myhynchon 7 ryfrchon }
my function 7
u
uTrmpor a Moctule 1 ~
==
( wey Boke babes i>
Cons' mnyfunchion = require ( -Lmyrnodate 5
ny hanchon O;
Oo TP usin named experts t-
// module is > ble name.
exports. myfuction = 0 > £
Consdle tog (“Hdle”);
iP
JI main js —> file name:
Const § yay fonction = Sepuire C' -Lmedule'),
ing knchon C); 40 output = Hello] g6) py
© Diloence bho Srequire and fmpord f0 Node js 9
lohen would jou fuse one over the oher,
Ans,
- = . modules or packages
Both are Usect to fnclude 4
én node js
> yequive fs he purl donor TS madlule Myst ,
fs de.Js.
which is the defartt madule Aysiero 4" node js
ahich is the
72 Topo as modern module ofysdem oh
part ef ES6,
Syataat i=
=
require + . e
Const expres = reqire C expres }
Smborh
impo
Gmboxt express from —‘expyess' ;
caning execubon is
—> require voorks synchvorowsly im
Mecked. unk! module ts ily Loaded.
Ths can be Gnefficient - when Lovding Garye modules:)
)
J
:
)
y gaporh ts Asynchronowsty and coorks by rabically an
the build preess , This leads to herformance bencfils
i
Fe Bean Soustre ds older awl 5 SHI widely Used in
[7 ees abies.
npm 2
Soh Tostetl
Unis tall :—
=——
G: How de You install , update and femove a Packeye ust
d
ny)
for loca) \nstellabion ,
Pm fnstbl Kfeckape name 5
for Glob insklladon .
Mm Anskall — gC Packepe-nene >
pra Update CPackejename)
npn updele —> for ait ovtdlated puckajes.
npn uninstall Package name Y
npm uninsall -3 K Package name > 9 renalQ: ¢ .
Ny What Ps Express. js ant cory do we Use tt iy
nade js abpiiabion 2
= Exess fs is popular web famevoark That yuns on
nedejs . fF Zs powerka framework widely used
GF abiinplifes touting , gopports mddlacare and
dev building APTS city Ooh ef dlexibility.
because
as perfect
—y Ti helps in manaying HUrP requess ancl respon
Q Simp)ibed ‘roubng — You can creale endpoints for diferent
URLS and define Rinchonalihes Lite
Cock, fost , Ped: aah ee. for each meuke
© Middleware fpr 7 evar expres aes you to use rid lesone
cos Moth ease,
Gaathons that process yequesls In behxen
Such as authenhahor , Long or
dala valtdaton
@ Effient & building APL 2 TW is great dor cxeliy Res} APL's
qwicks, and easily.
@ Flexibility + xpecs gives you gull nol over the dervers’
Inchwior , user Gn build backend shuchire Qccordin
fo tts o1n call fneod
J
a eh ke0: 10 ua hand) o <
G: How do ou handle HOUNS Sn an —_
Can you Shoo a Stmple Soube ne “PPlicaton 9
bh — :
Sch Thom express appication, tous «
OC Used
ond} , ‘40 ‘abl,
endpoinls Curvs) and tre Logie no. deine the
ul cule
ot he
fine f client dends & Sequest do thal ue
Steps to handle Roules :-
1. Create an Express Gp - -
2. Use the app-get() , App - pos), pp. pur) Ab dete
; cht)
methods 40 define Joules pe Aiffexent HTP. meheds,
3. for each route Spedfy
=~ URL fal using slash (1)
> Callback Kunchon > cahich Conkinhe Lage tat
uns when he youkt is
‘ees.Crealn lowle ‘“
1) a Kowle dhat responds — with “Hello , voor”
Const express = Require (‘express’) ;
> I Sibalse an expoess Opp
Const aph = expres OC);
Skp:3 7 I) oehne a Olimple GET Foote,
apg (1, Che. 908) 2 £
a Send response hen
des. Send (“hello world a
dhis woul 3S
s ) ‘ accessed.
Skpi4 7 Start the deer.
Const fork = 3000;
app: Ashen ( fort, (VO ¢
Console: fy (“sewer is Yunning 04 4 Storr} ) .
);oe ou)
, middleware 1 Express-js 9 Cao JO Wtve an erg p
‘
(hal
Se se 15 used ina Node, app 9
4 foc middle
of
ty
posi Middleware — defets $9 rections Hod erage
behween the Hreques’ ~ Hes)e
ose hel
F Midtasere Rencions have access fo the eyes} objec
A object,
Sespense Ohfeck and the ex) function
> neck fnchon passes Control b the next middlasare fanchy
or to wouter handles.
> Middlesaye can her for Various tasks luch as.
j
@ Esecubny Cod,
e O) C.
Q Mel ig the heques and hesporse objals.
Q Enchny the hee - hes Gee.
© Pest Gnhol fo the next mdse Latln fe
slack. :
7 Midllacare fs essental dos handeling fesks tke aothenticokon ,
Foxy data Velidetion ees9}
OO
“Types of Middleaave s-
D Abi
@ Appircahon —level_Middlecare
& applied on whole @pP
p.use
& pind ferougth apy
\
S
Ly Specific for Rowke™®
L bind throagh youter use O-
Built -7n- Middlarnre
Comes with express ger paxsing
Json hoelies
& ey express. So” Q)
Trad - party - Middleware
& Tnstalled from NPM
an afor 109ging-
Ge: mM
deling Cyoss-origin 2€(eesh
Corsafor han“a
5 C sare fy Node js 3
of Middlaowe
xample ¢ (
—— = a =
Const express = require C expos’) _ bcbg
on$ :
Const app = express O; ie
hale the express app.
Goi sewed boyer = Corey, 965, nexh)> ¢ Cre
& middle...
: funchon,
Conse: boy cn § eq vnelhad | Mog va \
next ();
ci
Gbp- use (requestlogjer) > Us the middlaner
app-ger CM, (ney, ves) > oon eds
Aes “Send C" Hello world”) i
vj
Const fort = 3000, EE We see:
PP: Vsten ( Port : () = §
Consele. Rey (* Sewer is gunning om 8 {fort} );
5);G: Hoe would You nplement error ~ head ing middle vowre:
ir express 9
3 Exor handling middlwoare in express ts used to whch
exrors and hardle ther appropnately _ tke Gending an
emer os teging the enor,
= emr theoding midi ave fundions ave phimilar 10 regular
middleware bub with only one dtfexence fre,
they tXe fu arguments Faslead of treee;
Cer, NG, HES, next) s—_,
Q: How do sou read and wate files Un how. t
Z de
/ a JS Usty 4
fs module 2 show an example of J rely a fit 0 the
Ca
Deora 9 .
Arsi The £5 ts File Sysiva meddle which ts Used 4p itheraet
= ¢ tral est
file Systm - Tt provides verrous mefhads ty read and ovis
¢ oyite
fies , both Synchronous! ¢ and asynchronously,
> To Sead a file Asynchronous y , You Use £5. real File ()
method , Which does not block the execution g the Prorat
7
Tr reads the file and Calls the provided Callback unden once
the Operation fs Complete
nchyono us! ae -
Example of of Reading a Ble agynchrono
Conse fs= repire ‘Psd;
£5, Sead File (example tet ' ‘Ue- 8 - (erm, da) z, i
4 Cem) §¢
Console. Log ({ Evo reading the file iy err);
sneha 5
5 ‘ file Galt as
conso\e- Nog (‘file (anes: , data) ; antes
5);Ex plainedion ae
° fs -readfile () 7 Reads th
© Conhent a a file.
* fivsh parunckey —? The ie bb (' crample Ech 5
+ the encoding “ues ensures the frke és
Sead a5 a Bboy -
* Second RavumeX?
s Fire PavamehkY 9 Callback function dhak recteves the
ermy (i any) and the pred.
roy , the Content 4 the
n > af there fs no e
jn the dala variable.
ae =
© Callback funcho
file Us availble
Eronble of wibey 9 Ble asyehwoncusly ‘=
Const fs = Sequtre C457);
fs .usate File (‘outps.? 5
4 (er) f
Console. CVSOr ( © Eyror vonting to
fieluen 5
5
Console: fog ({ Ble we
‘penowore’, “UbF-8", (err) 2 §
re Bile. 3
n sacesshiy , DF© fariieFile C2 7 Wiles @ Content fo fi
le.
« fivsk Rvamedey 7? “Tre Ale path.
+ Gecond Parone =a The data You wank qo ove.
« Tived fase} = Tne encoding Cupt-8?.
© faath Qaramekey 7 AA cali back tat gels execubed once the
gare Operahion is Completed , cahich cn
jandle any pokatial esroy.Q: Can fou explain whak Sheans ae i Node js and how
U
they dks from Hradihonel data Sreacing [rovshay mefheds..
MS! Sheena Wa AMAYES WOE AL tery. oy eslie ending
catty dels Fee OEY ak WAKE - Taig, kes eSheaacas
RA ieenk
Streams dn node js Gre a wee to handle Sreading ov
vowhny data in chunks piece by prece , athe Than foading
al the data énko memory at one. this makes Sheams
Nery efieient , especially for handing faxye Pes or data
Anak Come souly Ute cudio video or nehoork responses.
Why are shream Useful -
> When we Yead oy Worle cleda In a tradifional “997 Uke using
4s .neadite () , the enbre file is ryead fnto memory before we
Can seth. This teadihonal way coorks fire dv mall ples
hak #5. fneffecient and Can Cause memory {sues for large #les.
yz cotth Streams , data Is processed as Soon as i+ Star}s Coming fn,
chunk by Chunk . THiS Means we don't have do coat foy entre
fire tor dala to foad byore doing Gornelhing with iF,Tybe J Ahreams I —
@ Readabre Sheams —» for dealing aly,
,
,
1 @ Duplex Shreams = —® Can vead and ure
>
@ WHlable Shes > Poy towing dala.
ab da
+ Nehoork Connechons
@ Transbrin Sheuns Modify the
me Ame
daty While Seadin} oy
Coming (9: Conpresiny files)
Advantage ¢ Seams »—
@ Wes rnemory —effectent,
@ Faster processing = a5 data geo sherts Coming inskad ef
taaihing for Whote it Shark Processing
@) Real time Use = great for Shreaminy video or
handling doge nehoork Aepucst.
fee © © © ee Oe © © esQ Work ave fhe difference bud
Callycks , Promises and
async | avail in node ss 9
Ars: Tn nedejs , Callbacks , premises and async Jawa ave
diferent Woays to handle asynchronous operalions +
‘ ( C
i: Callbacks a
Al @allback ts a finchon dub is passed a5 2”
Cement do another ob funchon , ard ren
n Wes
asnychrenous fask 4s Completed the 4,
Cahed.
eq: ps
DB funchion gerserdada (callbacks)
$
Set Trmcout (0) > ¢
Const usey = rene John’, ayes 30 3;
Callback Cuser) ,
§, , ooo) +
etuserdala ( (user) =) S
Consde Ney Cc name: 4 {vsernune} 4 Age: § { user.aye} )
3);X The problem uty Callback 45 that Cohen there are ans
Calibacks ie, there 1s nesteel Caitbacks — fhan th leads fo
Cattback rel ohich make Code havd fo wead and Main
ee
Q ¢
Prmfses :-
=>
2.
> Promises fs an Objeck that srepresends the SeselF
{J asynchronous function BrediBoe i, ether he
wark % done [ sesolved ] ®&) thee is any roy
£ reject] 5
—> Tis beter than Callback 5 TF altocs cheng
Gnd rakes ery hendelng easiey, and tk Kechs
U
Gode Clean and Shuckned.
> Prcorice Bwe cal yesolve (1 when Code 3 Successh)
and We call reject () when exToY comes,
— sthen() handles ohuccess
e catch) hanlles eyrors,
7 Th have 3 Steyes
O Pending
@ Resolved
@ Rejected.Sh vation -Bierdate
g le} cheetbvenNomber = tuackon (norrber)
¢
aehern new) Provmise ( fonctor (sesotve eject)
§
ij (monber #2 === 0)
L
freso\ve C g Savmber} ts an Even nombe? »;
4 else
t ~
ajeck (> % Srarber} as net Bere yy
3
II using the promtse
Check Even Nemb ey (10)
sthen ( Gressege) =? £
Console - toy ( messeje);
D3
+ catch ( (orn) >
Console Qo (exo);Asyne | fusit
> Asyne
bod ty yt Is easier and ft
EES Gilles
i ts based '
[avai ed on promises only
woskiy asy nchoronees Code that fook more
Ake yn hyonaus Code , hich makes 4
easier do weed and maittzin,
7 asyne guachons frehrm 4 promise and We
use quait t pause the exeeachon whl Promise
is pesolved.
2 tny| ath blecks vt used fr handle ens ,
making fF sasier handle both dhecess and File
Cases.
meen st @) eee ,
aft
a
ce aM
Ks
¢ Sicko ne promise ( Caesolve) 2 ye pee Re sole
SerTineout (C) >) § a dee ral
gescive ("Dada peciwed )
ve (000). ; Console: Los (date) ;
See 3
asyre. finch getdolaC) nk cateh (err)
t
{
my 4 Console-en07 (e075, e
Const data = anak felchata (): i.
aa-daty ();
ey
vyQi Conert the CaMback —rrsed dundton ha promise based
function .
funckion — feldhdala (Cattback)
: set Finca (> §
Cal back (* Dala felched"),
¥ toe);
4
Ars Racion felndata CD §
Siehym new promise ( Coresetve , srejet) > §
Selfmead ( O 9 f
pesove (“ Dale fetched” );async funckon gerDada (
£
Const daky 2 Guoaih Lerch dala ();
Console fey (data)
Je Date C);
Q: How would Gor Connect 4 Node.js app too Mongong
database J vohat package de gee typical use 9
fins: To _Goanect « Node fs app Goya Monjo06 dakabase we Use
=
the Mongoose Packase
> Mongoose 48 4 Popular ODM (object Data modeling) hibrooy
for MonyooB and Nodefs..
> Mongoose provide @ Divek voy to tnkevack with Mopyod3 including
defining Gchemas , models and tandling Queries,
> Dy Stplifies Queries, Crud operations and relafonship behseen collechens,
5 Tralso provicles built 4a validabon ee Deki.
Sopptk in defing pchera for gous dafa gnd alse hobo
middiasare .),
Gg What 9s MonyoD8 Compass and MongoD8 Atlas 9
Ans:
== (Monjod® Compass} :>
Th tsa graphical User Thier ve for
MongoD8 fat makes ft eas] fo work oth the Monge DB dakbise
wHthouk need to worte Commands fh the Hetmind
TDS provides @ user Prendiy fesfice wohere gov can easly Panes
Your database, cotectins al douuments . one can perform
things like Crud through the Visual tntertce »
M DB Atlas}:
[Monpoe Abas)» Tisa Cloud Sewice that manages
se one don't have 19 way
MowoD8 dakihases y Phe User,
: ; delabese - Tr Tuns on bopulay
About hoshiy oO rreinkcigg the
Cloud platforas ike Aes geal Clad ond Ayive
ou
; nani Je Hon DB dakbase
ge els to deting oP, ers ard dealt HOnpl
anthe cod with very Aitte effost .
\s of Tunas dalabsse dervets.
User don't need po hondie
dye echni cal detail—=
that fs Body Parser
Body Parser isa tool fn ERM Abplicadion tes hey
express dewet ynderstand the data ‘hal Gone nelps
S from th
Client fike hen you fill oF @ fom sind Subatf me
then Frontend sends dota Jo the backend , thet dala car
be in different formals fke ISon ov fore dake, bel
Parser helps express understand this data.
as it takes the fncerting date
Hin
Tr makes data fasy fo vse
Gnd pas eh in rey body So user can easily access
Sewer Cede.
seis q built-fn midd leoare .
a~~
G+ what fs muller nm Nodejs and Why do coe yee iho
fins: Mulley fs a middlerame backaged a & module
for Nede
which fs osed cf express Aphicahons to hangie file
Uploads . Th ations fou to easily Upload be files fom
Q chenty to « cher,
Why do we Use %s-
7 User can upload Giles Itke Finges document ete ‘trrough goms
On website | muller mgkes these Uploads easy to manege |
> Thhenlles differnt types Y files and allows USe¥ 4p Shecify
Lirtls ontne dne and dyhes of file that can be uploaded.
>
Mutter dieplifies the process
4 aecephny piles 1 So usey dont
teve 1 wile Complex Code.
Mulley can be used to dhe
file Aystera.
files in emery o¢ on Cewer's
[i val a],
1 Gs Explain M¥e acchikechre in nedejs sank food -tould ou
' Shuchire gq Nodes apprcttion using it 2
Gol: Myc slands fyy Model, Vido and _Conbolter,
—_—' — —_
@ Model :—
es
Te aepresents_the dota four We define clafe
Sadveroas 4 rmeelel and th helPs an fabeeachig
with the data lore
© View :-
i Tt reprecents_the resentahon Loser. This pense
fos whak we See, Gach as HTL , C58 and
client Side Fevasesp
© Conholler :-
ay sebreseals the Loge er. Tt handles User
aequesls , process them and cleternines (chat 4
fn response. Jn other coords, WIL
APL in Conbpller.
render
ceep the +otal Safe 4 the
. _
Routes : > Th ts essential park ay Conboller layer. Routes
4s usecl fo Altre hoo the «pp handles olifferent
RUS (lek oh 1 cre Request:
uaes (hee erst ot Ses
7 We usb the wme\hod | endpoint and Contre fur
hert.Shuctrg a Node js ofplstion vsig Mc,
/ wodeds > folder
by yser Made) js 1 FileName
/ Conbvlleys
& Usertanhuler Js
] view
G userView gs
] souks —
LY UserReukes, js
Sewer js [Apr fs —1 Main file.
¥ thy we use Myc Architechive .
—~
b We Use MVC architechne fo organize and.
Abuchoe guy appheation ina coy that tlep rates concems
Making A move mange able, Scalable ant evsler Neusable.
Reusable ao 9 =
Ge Hode) and Con hwlies Can be reusel Across
fe ven inter Gres Clike
mulfiple Views « for eqs il
&
riidbile, Loeb) we can use the Same rode! and
Conner Logic bub epibeciblecent — presendetin Inger:eo Or ae} q) a
Q: what % Nedemafler and how would You Confpure H
Send emails fn Nelejs app 9
Solt
, = Node-mailey fs
widely Used nodejs module thaf- allovas
1 User to Chend ematls divecyy from a mode js application
Tt chibi fies the
process g Sending email oy Providing a
Grvenient APT Po interact ott email dervers using SMTP
> Nodemeley £6 dlesibie avd Support aendiag emails Lott
Phin tat | H7ML, Content and even attachmends.
> Tralso sepbork attachments xe dtendng POPS fnrages ek,
Conf pure Nodemailer :- : :
@ fnstan Noderrailey. > mpm ‘nskalf nodewajler.
@ Conk gure a Transborley you need to Cotte a franspovker
Object, The transporter Conkains
the details sequived. to connect oan
email dewice Provider Such as Gmail .
@) Create Mail phon —> The mat) opkons objeck defines the dehile of he
email uch as recipient ofubjeer and Content.
© Send the Emil > We use Send ef) ©) method fo Send she cneit.
This methed fakes Hye mail Offions and ends the
emai) via the Contigured ransposter.
a)QO: What & Email IS “ant hos does 4}
differ from Nelemailey 9
Email Is tsa device phat Mowe You fy
d
dovechy frm the cltent-dide ey
feat oy HtMt tom]
Bend emaé/ Ss
J eb a bteafon [Bete
wihot needing & backend oy sup Sewer,
> Tt provides easy inkepration with chenkend frenesorks and
(dorks entyely on the Chent-side, wh
ich means You don't necd
to deep a dewer or crite Sener Sife Code.
Difference blu Nedemailey ane Entei 75.
1, Where They are Used s-
Email 38 > Used onthe Client. side ize, Frontend
Ne backend 4 Sequired.
Nodematley -> Used!
on the Sewer ~Side ive, Backend,
Ts a past of Nalejs to handle Sending
emails Hhroygh SMTP Sewer.
2. Setup
Email.38. 3 No weal 4e Betop an ennai! Sewer. You just hondie
and Use theiy APT in frontend Gde.
Nedeynmiler 2 Tt retires a backend Sewer and SmrP ccnp guration
to end emails.ei)
SS! EE
3. Use Case -_
Ermil.T5 —> Best for Sul, simple appheations dpat clon’ need
4 backend .
ey Sending nhac forn ubmissions fram a
Stabe Website.
peer) ae) dor Rarskck apphabons tohere User
Alrady fave a backend Weer in place
and provide ang GBF more conbol over emai okending9: what & Jor ad
thy as # Common ly used for qutte
dn Node Is abpleaton 9
Ans:
Jwt [ Tson wer Token] f¢ @ Compact toay of Seanely
between partes @sa Ison Object .
is mainly used for Gutheneahion and Guthorgahion tn Wweb
Gpplicabons . Jut atiass she gener to verify the token &
tense iting fnformation
ae
Guthenkade users wttheud Stoviny dlession infornken en the
Wewer itself.
How Jwt works --
1. User Lojs We ‘the $304 Sent: Har dogin info (esenarse and
Password) do the deer.
Server Greales aq Token :—
TP the dejan is Comet, athe Sever
reales a JWT and dends # back
do the User.
: User eres the Token :- The user's browser Stores His toten
usualy in Local Storage or Session
Shoryse.y. User Bends Token By Necess -—
ale Each time the User voanf Dd Ue
He protected rete f Ye part y
the dite , they send this token
alony (ith heix request in the
Authorigeden healer.
S Senet checks the Token. ye deer checks the foken to
SS
make ure itis, valid . IF *# és,
che user tS allowed fo proceed.
Why is Sw Commonly Used :-
> This decuse as foken ts digned with Becret key ,$0 tfcan'+ be
Charged thouk the @bver Knewing Tis makes fe do use
> Works well ith mobile and “seh offs. ie, Can be easly Shared bles
diferent Systems.
—y TOT are ay fo Use asthe aye mall and canbe pased avune
in up's , headers ar Cookjes making them fledble.
> Th Just jAhe foken tsel® Gavvies the User! deta.oo OAuth 9.0 works 2 How could he
i
@: Hi y Goplerneng hing
Parhy authenbication (ej. Login vis feogle on Facebok), Nodes
9
=
~S
Ans: Ofdh 20 is a methed that allows user fo Loy nh @ lochsthe
using another account they alveudy have (tiee Plea Petey
witheat charing freir faxsine passwords with he news Heth
Qlled tyre party authenh caon
Isis
How ofuth 2.0 works 9
1. The User ches on dedton thay dys Lejin with Seople ox facebeb
2. Then the user is daken do Goope) fi
Usex fg in.
3 Abe Lossing in , Grete | facebook asks the ure Y they count do alley
the new website to acess Some basic informabion | sheiy emai) and
name
cebeok's Login pose hese the
4. Uf the usey apres, Geesle
| Facebook sends a Special cocte cated
an aces token back 4p
The Cc beite,
PPLLL PLP PP LLLP Ppp ppp py 9s
5. The wWebsike yses His foken
Dgthe oser$ Inform acon from
Gale [ficebook
and dogs the OSeY tnt the Ste.
(LP PLL.a ——_——eox_— & ©}.
Wh
J OAuth 2.0 is used 9
Securthy
User clot have fr creafe e0 passwords oF
“Nes _ They just
count.
Share them cotth multiple Wes
use they exishng Coegle ] eebeok =.
3 :
Gr venience »
ccounts they
Tes foster for users to Lagi with &
lor
already frove, fasted of Creag reat oncs
every website .
How to fmplement Ofuth 2.0 in @ node js APP?
41. Tost bt
Tastan Passhat Js Wir is Vibra which makes fF easy to add Geafle,
Facebook or other third focky Jegins.
[Tiber stall _passpar? _Pashat -gogle-omwh20 passport Pacedeck. )
2. Setup obi _shetey
% you setup a Shrategy” in passport for each
Provider by rovidicy geur app's Cheat 1D &
Client Qecre hich you set from gegle /
facebook Develcher Console.ee
Greate ovuks 40 Star and j
pinish he
dggin precess .
€
g
¢
¢
‘
4. Handle User Data a
ae ' (
Aro gin , Google [Facebook herds the |
Users info. you an use $e this dafa
do Greate a new usey in sor opps
database or Dos dem if hey Already Ost.ee a ener
Q@: ;
Qe Stateless and Sharehur Authentection 9
Ans
2 Stateless Authenticaon
© TW sas Shabeless Authenticahion ) no dession dota ?s Shoveel o”
the Sewer
@ The Vsex as Authenkaled using a foken (ike Sot) that iS Gent
Lutth each Sequgst. The doken tiselP Gearies all fe MECESSSY
information,
@ Ws *s Ligh waghh and seales easly D
need to Keep track 4 users.
poe he over des eb
Statefu Authentication .-
© Anttis, dessin daba fs Stored on the Server.
@ When a Usey dos fn , the dewer creates a Session and Sfres
on Qhouk the User . The client only dderds Gee a
informe
egpesls and he Clever checks the desston
dessfon ID fn ach tt
dda.
@ aris veeures the daver Fo mange and hore sessims , Which
can be riot fesource fnkensive -@: How to handie Ewors ina Nodejs Applicahon Gael aa
are
Some best prachices for morgy'y) emp ab cli fferent evel
(eg. dynchronos ys asyemonas code) 9
g
Ans: Tn Nede js bP , enor hand eng is. toporkin} do ersare the Smoot,
be manged proberly.
‘yun ef app and ff thee 15 ay ise tt can
Tn Synchronous Code:-
8 Use trys Gatch blecks f Galeh enors tn Syachrones Code
gy gf
I) Code fhat throw &" enor
5
Catch (evr)
II hand the Over.
.
Tn Asynchronous Code,- [Promises]
© Use eCatch () with promises fo handle Ero:
ey:
2 myhindion C) - cach (enor => £
U( handle the eyrot
D;In Asyncvvoness Code :- [ Asyne| Await]
ie Use ty catch blecks around async Ranctions
Ss Asyne melon imyhencion G
1) Prsaik omething .
5
Catch (or)
|) handle The €nY.
5
Best Prackces fr Han oping Gro:
> Use a middlasare to handle
© Cenbulyed Esvor hendelin
8 J
all frtows in Express. -
Q@ fog Exeos 7 — Alusays Joy enors for cebygny-
@ Graceful errr Mesays =? Send user jrlendly enor messages
to the Client coithat exposing
Sensitive. info.
Tu. a
* Eyjaccah gerbe) Sync _and_asyne Code j promise. Calzh o()
ewers in promises.GE What fs rmengod8 and tshy we use 7
a Monod is a No-Sqk Database that Shores daly tn
Ffleible Tson-lke documents inslead 6 tredifional “ros
and tables Like SQL databases . Th is designed to bre
large Aeale lata and Can easily adapt to changes in dota
Struchure.
Why use Use it e-
© Flexib\e Dota Model 2 No need 4o preddtine @ Shit Shuchre .
@ Seatable > — Be tundler Sage amount of dala avd Can be
Aishibded across mulliple sewers casi,
eter for Modem Abps
® Een ene 2 Works wel with Savaseript and Nosejs
eshecally for real Ame apps fire
E-tormerce or Decial media,
CCCTIAOCLAL AERA ERP ttt
Y
qQ: Define shayding 9
ye Shard fs the process 4 spriting data across
mulbple dewas tb Manage vey lage daksek.
© Tt helps Monyon8 to handle high deaffic by Ashibuiny
deter cevoss Several Machines , ‘improving pedfermance.
WB
Defense Detatoates th Hoyen6 9
Ge A database in Monyod8 isa Conkiiney for Gllechens.
# Each database can had mulfple Collectors and
each Collechon conkins document -
SS You engi have database casted Catfeny Abc” thet
lontrins Collechon xe “Enpleyes" and “lepordmen ts”.
q: Define Golleckons %m MongodDB 9 ‘
Lo A coliedion is [ike @ fable tn SQL but more fleribie .
Bi agrovp J douments thet Con have different
Srruchoes. -
ef: A Collection Jor “users can have ABtumais co
different fields . one user might fave an email another
night have both emai) and phone number.Q: Define Replica Sets 2
4 8 A sepia deb is a grup 4 AeyoDs Serves
thal keep the Qlame dala Gfies.
* This Sebp provides igh availbliy and fault
dolevance ive, if one dlewer gees dun , ote
can Condrue tb gewe dla.
&
S: Define Thdexes 9
Ge Thdexes help apeeel up dala efzievel.
e They work ke an frdey gna book 1 making # easier
te gird dowments by opedfic fos (Ske Secchny
by name or td)
# MonyoDB allows youds Gaeake Andeses on any field ,
inproviy pestoornance por qweries. «
Define Gudfs 9
by fuilfS isa Fahne fn Monpoo® Het allecs Jou to shore
and whieve large fies Mike fmage, videos et by
osplrtipy them filo Qmgller paris.
S
wCS
. Def; '
5 Mongoo6 Suppers mutt ~ docanent fransachions
which ensures thak a Sexes ¢) opevahions cithey
AW Succeed @ alt jail | sioatlay fo SQL Database.
hoo
& ¥ Lookup > ferfoms a left ower join behoeen
Collechions «
gyapr Lookup 1% Performs a recursive Search ona Cllect'on,
Allowing fe more Coraplex queries , Such as
graph based data Shuchues.
Qs Find C) vs Anne Cin Monge D8 9
Ags: find 2 Rehons a Cursor fo all clocuments that
a match the query cutena-
fmedne () 2 Rehoms only dhe dist document ‘that malehes
_—_——_—
the mer Citeia.
Gs Howe do You ensure high avai lblity in Monjoo8
Ans: High availblity In mongoDB PS ensuved though the Use e
repiicasels,, Shee cata is weplicatect across npalhi ple nedes -
Tote event dja node deluxe, a Secondary node js audorahcall4
p :
Promoted to parte ensehing Goalnee operahions.@:
a):
Puspose 8
Update ()
_——
Save ()
es
=
2
updede © and Save () mMedhods fn MonpoDB )
Modifies exishny documents Pn a Collection
based on & filter - B allows fox perdial
Updates using Operators IiKe § Seb,
K onset eke:
th the documents exists ,it upelaks tt;
Othenuise , 7b inserts a new document .
This typically used gor upserhing ize,
(upadte or insevt) .Q: Di ference blo
MonjodB and Mys@L fe
fas: 1. Data Shuchire :-
Monjo0® > Bs stores dala as douments ohich
SQL 7
2. Schema :-
Monod @ -
Sau 7
3. Scalability in
Monjod 8 °
Sou 2
Can have diferent _Shuchaes.
Te stoves data in tables with
Predefined rows and Glumns he,
Shick Styuchire -
Siu ee
his shemaless ie, no need ty clefine
Shuchre beforehand.
Th have fred Schema re, struchoe ¢
clala is defined bgpre shoving #
his easly Scalable , handelins Large amount
Q lola by dishibactag Ht across mulhiple
Sewers.
Tt Scales Verbvcally bu this Challeng
to kale hongenay aewss mulbple
dervers.
—~Define Cors
Corse, Gess- ovigin is @ ‘way Fo altoys
Resouvee_shanin
stke fo request data frm aneter qwebstte . THis
because bwwsers pleck ese Hequesht fey
ame &
Smopevteant
Ga pheuniy seasons qn by usiy Cors, a sewer GN aliew
u ¢
Cevkin Wwedsiks fo acess tls defo
— Covs fn express allows sewer ty hand/e reyuesls frm
afferent domains.
4 To Hanase Gors we use Q middleware called Gr.
This middleware allows us do det which domains Can
access your express APT oreebSewey:
BD Const corse neptne (‘cors) ;
apb-use (corso); IL Enables Cors fo ail youles .@
Ans *
VP wg
tht ts f8. 9
> API ee, Applicabon Prernmnty folerface is a det gy
auyles fat lels to applications Hulk cach other. Jor exanple
when we Use & app do check the helher , Ph uses an APL
qo requesh the whether date fran another dewice .
‘Fovent obystorns fo enterad aad
Apis makes ft euy fy ai
chart Prforraion
(what fs bufkty in Nede.js 0
A bufler ts « HY fo dive yuu b
Tris useful when gout nee
date from Hye inkemer.
thar clala Jeraporavily
fn Node js - d to work with dota
Streams Mike feeding Giles ov recieving
What ae Cooktes 2
Cookies are dwell pieces ¢) data that websites Shorts on %
users browser tp remember frfunahion about them. This clafa
As qhent back tothe Serves everyhine the user visits, the. Sie
Agni , helping the oie secyynige the user ard provide a more
pevsomligel experience . ;
ie 3 ce for ey: Login sessions Language preference
Conch it
onch (ovkieParsey = yequiye ( ‘Wookie -farser'): |Wey
Whak is berpt 9
eel
Pas: Anis @ beobulay Ecbrary used for hashing passesord securely
Kegfeziny before Shoving them ina database . It ensures het
the passwords we Shred ma aefe wey by converting ther
na encrybied forme So thab if attackers ger the access
e\ dakise yeh they can't Sebieve the aniginel passvocret.
Boybr is Smpoytant because ¢ :-
me ee
© Hashing . bewypt Ayansforms the Password into a doy Shin
ae ed
4 yandem characktrs and te ongined Pesvore
Cannot be reversed from fhis hash.
@ Salting :— bewpe add a extra Leyes J Secuny by adding
@ random shiny (calkd a dlalt) fo the Pusvord bby
haship} ft . This ensures 1f fuo users have dame
password jtheiy hash value coil be diferent:
@ Slows hashing i byer beayph is Clesined fe be alow , mneking H herder
fey ghackers fo use bnde- force methals ho qless
Passwords,G: What fs ayyregalion pipeline in Mono?
(=) Nt poerfiar feahine used for Processing and
hrans forming dala.
> Th alloss tv perfor operaion in Aequente ef layes
> Eah dleye Can perfor Opevedions Bice 4
- Filesny documents.
— grouping dota.
— Calealabng aneryes.
data effecienlly
an analy3ing and transfor
a B gor dalabase.
a Tt help:
insights fro
mating it easy to gererte
G: het is_doeny_in nae 7
Aas: senv 35a node.js package thet harps to mange environment
variables easily. T+ allows yo to Store Sensibive infogrnahion , Nike
APL Keys and dedubase URUS gna serv file fnskead gf hardeodiny
thern inthe Code. ize, Tr makes usey to Keep denstkve chia of
4 lode.
J npn “nslall dolenv.
J epire (‘dolenv’) config) .7 Locd ct dhe Ip of
: min file -
% Must add senv tile to ott Woe. -
Vg: How to Jem ov Connect - Rontend and“Gackend together 7
oy
Can You describe Your approach fo developing a fu
Abpicahion including the technolagies You would use for the
front end and backend , how would you handle data exchange,
UseY qutrenbicah'on ancl aleplay ment 9
shack
Ans: Ina Typical project, I would build a Restful APL using
Nedejs and Express for the backend , which intevack
MonjeD8 database . The Frontend would be cleve leped using
React where f usould use Axios fo meke APL calls to
get deta from the backend . Date would be exchanjed in
son famed and 7 would hendle user authentication
using Wot. for Deployment, I voculd host the backend
on ‘Heroku’ and the frontend on Vercel, ensuring to
Configure CORS apps
requests.
Addi#onally, I would Ymplement fechng J the APL'S with
the hele 2) Bile Vite Rsshinan, too! Called Poshnan .
priately to allow Cress ~domaty)a Achema In MERN 9
\ Wha .
$+ What Schema and — Define
¢
A ahuchne of the deka in Moyyooe
Schema brmartly sefes to the
Th is
clelined tasny Mongoose cahich is @ ODM" lbroy in Nedejs.
Definmy a Schema in MERM =
: *
g Meyoose ees We define a dchema using monyoese
de desevbe fee Cheat fe eye
douimen}, This includes dpecifyiy the
Prelds, datalypes and any validation rules.
de] Creation :-
@ oes Once the Scheme is defined you create
a Medel fron 7+, Which allows fo
Interact with the database
fea= CRud document].
tegration with Express :- odels
@ a J The defined "can beused in expres
gpoues 10 handle HTTP Aequests
and responses , allowing sey to
perform CRUD Obevabions on Dofa.I] Debine the Scherta
Corst usevSchema = ned mon
usermame + 5
Npe: Shiny
required > tue,
unite: Ave,
}
’
Password *. §
types Shing,
reuned : hue,
as
1
3);
I Create @ Model frearScherte-
a ce
Const usey = mongosse .madel ( User’, userSchema),
I Export the Model-
module - exports = USeYUsing dehersa in Epress:-
Const express = hequire C exprese");
Cons USEY = greauive (“sImodel /user”) ; ]]fAssoriny the Game pat
fre, Schertq i User. js]
Cons} ywuley = express. Routey O;
I] Route fo Grate @ New user;
stouter-Posk (' Laepster™ | ayn (sneg, res) > £
Const § usemame, passuord $ = reg -body ;
ry f
Const newUsey = news User ( § username , fasswordt);
Gaait newiser. Seve ();
“yes Skabus (201). json ( { message: “ usey Lecated ucesshlly 2),
5
eh g Caleb Cemos) ¢
ves Stahus (Yoo), json Cimesye:" ewos” $);
‘
3);
module exports = trouter;
aQ: dence bl Schema and Mader 9
frst Schema defines the Shuchwe | 4 dowrvea} jy Many 038 Clichy,
Tt outlines the (iets, detatypes and Yaliclasion,
A model is a Compiled Version gf Scheine which alows to
inkvace with dalabase ire, Aeting You per brn operahions
as fhke Ceup usin SurmSunp,
Th Shot +
Scheme ddines the
Dhrchire and jules y the dela
Qnd mode}
is a Constnudy thee allows you to Creede
and mange dowments — hased on thet gchema.
7 dehema ts q JSlueprint and Model is fovs ox interact with
the database, 3