Consider this simple Next.js server component that fetches data and renders it. What will be the rendered output when accessed via a Node.js self-hosted server?
import React from 'react'; export default async function Greeting() { const data = await Promise.resolve({ name: 'Alice' }); return <h1>Hello, {data.name}!</h1>; }
Think about how Next.js server components handle async data fetching.
Next.js server components support async functions and await data fetching. The component resolves the promise and renders the name 'Alice' inside the <h1> tag.
When you self-host a Next.js API route on Node.js, which statement about its lifecycle is correct?
Think about how serverless functions behave in a Node.js environment.
Next.js API routes are functions that run on every HTTP request, creating a new context each time. They do not cache responses by default.
Examine the following server start script. Why does it fail with a syntax error?
import { createServer } from 'http'; import next from 'next'; const app = next({ dev: false }); const handle = app.getRequestHandler(); createServer((req, res) => { app.prepare().then(() => { handle(req, res); }); }).listen(3000, () => { console.log('Server running on http://localhost:3000'); });
Check the Node.js module system compatibility with ES modules.
Using 'import' statements requires the Node.js environment to support ES modules, typically by setting 'type: module' in package.json or using .mjs files. Otherwise, a SyntaxError occurs.
Choose the correct code snippet to create a custom Express server that handles Next.js pages.
Consider which HTTP methods and routes should be handled to serve all Next.js pages.
Option A uses CommonJS syntax with 'require', handles all HTTP methods with 'server.all', and routes all paths with '*', which correctly serves all Next.js pages.
Choose the best explanation for why a developer might choose to self-host a Next.js app using Node.js instead of deploying on Vercel.
Think about flexibility and control versus managed services.
Self-hosting gives developers full control over the server, environment, and backend integrations, which is not always possible on managed platforms like Vercel.