0
0
NextJSframework~20 mins

Vercel deployment (default) in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vercel Deployment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you deploy a Next.js app with an API route on Vercel?
You have a Next.js app with a simple API route under /pages/api/hello.js. After deploying to Vercel, what will be the behavior when you visit /api/hello in the browser?
NextJS
export default function handler(req, res) {
  res.status(200).json({ message: 'Hello from API!' });
}
AThe browser shows a JSON response: {"message":"Hello from API!"}
BThe browser shows a 404 Not Found error because API routes are not supported on Vercel.
CThe browser redirects to the homepage automatically.
DThe browser shows the raw JavaScript code of the API route.
Attempts:
2 left
💡 Hint
Think about how Vercel handles API routes in Next.js apps.
📝 Syntax
intermediate
2:00remaining
Which environment variable syntax is correct for Vercel deployment in Next.js?
You want to use an environment variable API_KEY in your Next.js app deployed on Vercel. Which syntax correctly accesses this variable in your code?
Aconst apiKey = process.env.NEXT_PUBLIC_API_KEY;
Bconst apiKey = process.env.API_KEY;
Cconst apiKey = process.env.VERCEL_API_KEY;
Dconst apiKey = process.env.env.API_KEY;
Attempts:
2 left
💡 Hint
Remember how Next.js accesses environment variables on the server side.
🔧 Debug
advanced
2:00remaining
Why does your Next.js app deployed on Vercel show a 500 error on a dynamic route?
You deployed a Next.js app with a dynamic route /pages/posts/[id].js. Visiting /posts/123 on Vercel returns a 500 error, but it works locally. What is the most likely cause?
AYour API route conflicts with the dynamic route causing the error.
BVercel does not support dynamic routes in Next.js.
CYou need to rename the file to <code>posts/id.js</code> for Vercel compatibility.
DYou forgot to export <code>getStaticPaths</code> or <code>getServerSideProps</code> to handle dynamic routes.
Attempts:
2 left
💡 Hint
Think about how Next.js pre-renders dynamic pages during build or request time.
state_output
advanced
2:00remaining
What is the output of this Next.js page deployed on Vercel?
Consider this Next.js page component deployed on Vercel. What will the user see when visiting this page?
NextJS
import { useState, useEffect } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    const timer = setInterval(() => {
      setCount(c => c + 1);
    }, 1000);
    return () => clearInterval(timer);
  }, []);

  return <p>Count: {count}</p>;
}
AThe page shows 'Count: 0' initially and increments by 1 every second.
BThe page shows 'Count: 0' and never changes because useEffect does not run on Vercel.
CThe page shows 'Count: 1' immediately and stays fixed.
DThe page throws an error because setInterval is not allowed on Vercel.
Attempts:
2 left
💡 Hint
Remember how React hooks work in client-side rendering on Vercel.
🧠 Conceptual
expert
3:00remaining
How does Vercel handle serverless functions in Next.js API routes during deployment?
When you deploy a Next.js app with API routes to Vercel, how are these API routes executed behind the scenes?
AAll API routes are bundled into a single server process that runs continuously.
BAPI routes are converted into static JSON files served directly by the CDN.
CEach API route is deployed as an independent serverless function that runs on demand.
DAPI routes are ignored during deployment and only work locally.
Attempts:
2 left
💡 Hint
Think about how serverless platforms like Vercel run backend code.