0
0
NestJSframework~5 mins

Third-party middleware (cors, helmet) in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is middleware in NestJS?
Middleware in NestJS is a function that runs before the route handler. It can modify the request or response, or end the request-response cycle.
Click to reveal answer
beginner
What does the CORS middleware do?
CORS middleware allows or restricts cross-origin requests from browsers, helping control which websites can access your API.
Click to reveal answer
beginner
What is Helmet middleware used for in NestJS?
Helmet helps secure your app by setting various HTTP headers that protect against common web vulnerabilities.
Click to reveal answer
beginner
How do you enable CORS in a NestJS application?
You enable CORS by calling app.enableCors() in the main.ts file before starting the app.
Click to reveal answer
beginner
How do you apply Helmet middleware in NestJS?
You apply Helmet by importing it and calling app.use(helmet()) in the main.ts file before app.listen().
Click to reveal answer
What is the main purpose of CORS middleware?
ATo control cross-origin requests from browsers
BTo compress HTTP responses
CTo log incoming requests
DTo serve static files
Which HTTP headers does Helmet help set?
ASecurity-related headers like Content-Security-Policy and X-Frame-Options
BHeaders for caching only
CHeaders for file uploads
DHeaders for database connections
Where do you typically enable CORS in a NestJS app?
AIn a controller method
BIn a service class
CIn the main.ts file before app.listen()
DIn the package.json file
How do you add Helmet middleware to a NestJS app?
ABy configuring it in a service
BBy importing Helmet in a controller
CBy adding Helmet to package.json scripts
DBy calling app.use(helmet()) in main.ts
Which of these is NOT a benefit of using Helmet?
AProtecting against clickjacking
BEnabling cross-origin requests
CSetting Content Security Policy
DPreventing MIME type sniffing
Explain how to add and configure CORS middleware in a NestJS application.
Think about where the app starts and how browsers restrict requests.
You got /3 concepts.
    Describe what Helmet middleware does and why it is important for NestJS apps.
    Consider how websites protect themselves from hackers using headers.
    You got /3 concepts.