0
0
NextJSframework~10 mins

Edge runtime vs Node.js runtime in NextJS - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the Edge runtime in a Next.js API route.

NextJS
export const runtime = [1];
Drag options to blanks, or click blank then click option'
A"edge"
B"nodejs"
C"server"
D"client"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "nodejs" instead of "edge" for Edge runtime.
Forgetting to export the runtime constant.
2fill in blank
medium

Complete the code to import a Node.js-only module in a Next.js API route using Node.js runtime.

NextJS
export const runtime = [1];
Drag options to blanks, or click blank then click option'
A"edge"
B"client"
C"server"
D"nodejs"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "edge" runtime when Node.js modules are needed.
Not exporting the runtime constant.
3fill in blank
hard

Fix the error in this Edge runtime API route that tries to use the 'fs' module.

NextJS
export const runtime = [1];

import fs from 'fs';

export async function GET() {
  const data = fs.readFileSync('/data.txt', 'utf8');
  return new Response(data);
}
Drag options to blanks, or click blank then click option'
A"nodejs"
B"edge"
C"client"
D"server"
Attempts:
3 left
💡 Hint
Common Mistakes
Keeping runtime as "edge" and expecting fs to work.
Not changing the runtime export.
4fill in blank
hard

Fill both blanks to create a Next.js API route that uses Edge runtime and returns a JSON response.

NextJS
export const runtime = [1];

export async function GET() {
  return new Response(JSON.stringify({ message: [2] }), {
    headers: { 'Content-Type': 'application/json' }
  });
}
Drag options to blanks, or click blank then click option'
A"edge"
B"nodejs"
C"Hello from Edge!"
D"Hello from Node.js!"
Attempts:
3 left
💡 Hint
Common Mistakes
Using Node.js runtime when Edge runtime is intended.
Not wrapping the message string in quotes.
5fill in blank
hard

Fill all three blanks to create a Next.js API route that uses Node.js runtime, reads a file, and returns its content.

NextJS
export const runtime = [1];

import [2] from 'fs';

export async function GET() {
  const content = [3].readFileSync('example.txt', 'utf8');
  return new Response(content);
}
Drag options to blanks, or click blank then click option'
A"edge"
Bfs
D"nodejs"
Attempts:
3 left
💡 Hint
Common Mistakes
Using Edge runtime when Node.js modules are needed.
Importing the wrong module name.
Not using the imported module to read the file.