Recall & Review
beginner
What are server-only modules in Next.js?
Server-only modules are files or code that run only on the server side in Next.js. They never get sent to the browser, keeping sensitive logic or data safe.
Click to reveal answer
intermediate
How do you mark a module as server-only in Next.js?
Import `server-only` at the top of the file (e.g., `import 'server-only';`). Place the module where it is used only in server components or server actions.Click to reveal answer
beginner
Why should you use server-only modules for database access?
Because database credentials and queries should never be exposed to the browser. Server-only modules keep this code hidden and secure on the server.
Click to reveal answer
intermediate
Can server-only modules import client-side code in Next.js?No, server-only modules cannot import client-side code because client code depends on browser APIs that don't exist on the server.Click to reveal answer
intermediate
What happens if you try to use server-only modules in client components?
Next.js will throw an error during build or runtime because server-only modules are not allowed in client components to protect security and avoid runtime issues.
Click to reveal answer
What is the main purpose of server-only modules in Next.js?
✗ Incorrect
Server-only modules keep sensitive logic like database access hidden from the browser.
Where should you place server-only modules in a Next.js app?
✗ Incorrect
Server-only modules belong in the 'app' directory and are used only in server components or server actions.
What do you add at the top of a file to mark it as server-only?
✗ Incorrect
import "server-only"; marks the module as server-only in Next.js and errors if imported into client code.
Can server-only modules import browser APIs like 'window' or 'document'?
✗ Incorrect
Browser APIs like 'window' or 'document' are not available on the server, so server-only modules cannot use them.
What error occurs if you import a server-only module inside a client component?
✗ Incorrect
Next.js throws an error to prevent exposing server-only code in client components.
Explain what server-only modules are in Next.js and why they are important.
Think about what code should never be visible to users.
You got /4 concepts.
Describe how to create and use a server-only module in a Next.js app.
Focus on file location, directives, and usage rules.
You got /4 concepts.