Yeah… data fetching, when it comes to async/await, is still mysterious to me.
Then from the bottom, since async and await are JavaScript before they're Next.js. Which part feels unclear?
All of the above; it's pretty foggy.
The problem. JavaScript runs on one thread. A fetch goes out over the network and the answer comes back hundreds of milliseconds later. If JavaScript stopped and waited, the page would freeze. So it doesn't wait: it carries on and comes back to the answer when it arrives, through the . Everything else is how you say what to do when it comes back.
- Callbacks: pass a function to be called with the answer. Steps that depend on each other nest inside each other: callback hell.
- Promises: a stands for an answer not here yet;
.then()says what to do with it. - async and await: promises written as plain lines.
awaitpauses this function until the promise settles, and only this function;asyncmarks a function that may await, and makes it return a promise.
Alright! I have the gist of it. Next.js supports both server and client fetching: what does that mean? I'd like you to use a data fetch as the example. And I understand callback hell now, so if I had three callbacks, how do all three get handled when I use async/await? I don't know if that question even makes sense.
It does. Three steps that depend on each other, get the user, then their posts, then the comments on the first post, nest three deep as callbacks. With await they are three lines in order, each waiting for the one before.
On the server. A can be async and await its post right inside itself. The await runs on the server before anything is sent, so the HTML arrives with the post in it and no spinner. In the browser. A renders first with nothing, starts the fetch from a useEffect once it's in the browser, and renders again when the data comes, so it shows a loading state in between.
1 / 4A request for /posts/42 arrives at the server.
Yes, understood better. But I'd like more on this: when is it useful to use server rather than client, and the other way round?
- Server, when the data is the same for everyone: an article, a product, documentation. And whenever the fetch needs a secret, such as an API key.
- Browser, when the data only exists there or must stay live: what someone types in a search box, a feed that updates every second, their window's size.
- Personal isn't the same as client. The server can read the visitor's cookies, so a page that differs per person can still arrive with its data in it.
Start on the server and move a piece to the browser when it has to react to the person using it. One page usually has both: a product's details from the server, its live stock count in the browser.
Why does a client component need to fetch data through an API and a server component doesn't? I know what an API is, but with this logic I'm a bit confused. Connect the dots for me.
A Server Component is already on the server, beside your database and your secrets, so it can reach the data directly. A Client Component runs in the visitor's browser, on their laptop or phone, with no line to your database; the only way it can get data is to ask your server over HTTP, at an address like /api/posts/1, a Route Handler that queries the database and sends back the answer.
I have my front end on Vercel and a database with another provider, say Convex. In that case the database isn't sitting with my server components? So?
Right, and that corrects what I said. Convex isn't plugged into Vercel; a Server Component calls Convex's API over the network too. The difference is who makes the call. Convex lets in callers that show a secret key. Your server can hold it, where nobody can read it. Code in the browser can't: anything it has can be read in the developer tools. So the browser asks your server, and your server calls Convex with the key and sends back only the answer.
- 1Server ComponentOn VercelHolds the key
- 2DatabaseOn ConvexAnswers
- 3The pageIn the visitor's browserGets HTML with the data in it
The key never leaves the server. The browser only ever gets the finished page.
It was never API or no API. It's where the call is made from, and whether that place can keep a secret.
Better.
So: await is clean syntax for waiting, one function at a time. The server fetches privately, with keys; the browser fetches through an address you make for it, because it can't be trusted with them. Default to the server.
Looking at Next.js's page on fetching data: what haven't we touched on there?
- Streaming: sending the page in parts, with
loading.jsand<Suspense>, so slow data doesn't hold up the rest. - Sequential and parallel fetching: two
awaits in a row run one after the other. Started together and awaited withPromise.all, they overlap. - SWR and React Query: libraries that handle browser fetching, with caching and loading states.
- React's
use(): passing a promise from a Server Component down to a Client Component. React.cache: so two components asking for the same data in one request fetch it once.
1000 ms. Each await waits for the one before, though none of them needed its answer.
Something a bit confusing is how Claude works in the terminal. We've talked about command-line tools, but Claude is also a command-line tool, right? So how is it different from ls or curl or any other normal command-line tool we used before AI? Because I want to understand this again: /plugin marketplace add bradautomates/claude-video
It is one, but a different kind. ls, curl and git do one fixed thing: the pick from behaviour written in advance, and the same input gives the same output. Claude Code takes a sentence, and a model decides what to do: which files to read, what to write, which tools to run. It runs ls, curl and git itself. It's a tool that uses tools.
And /plugin isn't a shell command. The slash marks one of Claude Code's own commands, the way :wq means something only inside Vim.
What's up with the name marketplace? It's a bit confusing…
Fair: it sounds like an app store. It's a catalogue, a known list of plugins and where they live, like the ones npm, Homebrew and apt read from. bradautomates/claude-video names a GitHub repository, author then name.
So when I install it, "both write to ~/.claude/settings.json". What are the files under .claude?
~/.claude is in your home folder, hidden by its dot. It holds settings.json, Claude Code's own settings, and a plugins folder where installed plugins live. Installing a plugin is mostly writing an entry Claude Code reads when it starts: settings.json is to Claude Code what package.json is to a project.
/plugin marketplace add bradautomates/claude-video, then /plugin install watch@claude-video. What's the difference? Why is one marketplace and the other install??
Two steps. The first adds the source; the second installs from it. That answer said the first downloads the plugin and the second switches on one of its tools for this session.
"Watch a video (URL or local path). Downloads with yt-dlp, extracts frames with ffmpeg, transcribes via captions or Whisper." What do yt-dlp and ffmpeg mean?
Two ordinary command-line tools that each do one thing. yt-dlp downloads video from YouTube and hundreds of other sites; it's a fork of the older youtube-dl. ffmpeg processes video and audio: converting, trimming, pulling out the sound, or cutting frames out as images. It's inside a great many apps.
So the plugin runs yt-dlp to fetch the video, ffmpeg to cut it into frames, and takes the words from captions or a speech-to-text model. The model can read images and text, not video, so the plugin turns the one into the other.
Then I want to know how these differ. If you say user scope, what does that mean for where the plugin is saved on my computer? If you say project scope, where are the files saved? Could you give me a brief idea of what this means in terms of file management?
- User scope:
~/.claude/settings.json, in your home folder. Yours, in every project, like a global npm install. - Project scope:
.claude/settings.jsoninside the project, committed to git. Everyone who clones it gets it. - Local scope:
.claude/settings.local.jsoninside the project, kept out of git. Yours, in this project only.
- Saved in
- ~/.claude/settings.json
- Who gets it
- You, in every project
- Into git
- No. It isn't in a project
The plugin's files are downloaded to ~/.claude/plugins whatever the scope. The scope only decides which settings file switches it on.
Wait. We installed Claude globally on my computer. So when you have Claude sitting under a project, what is that?
Not Claude: settings for it. The app is installed once, ~/.local/bin/claude. A project's .claude folder only tells it how to behave there, the way a .vscode folder holds a project's settings for the one VS Code you installed.
So if I have Claude Code installed globally, how does it talk to the settings file in a specific project? And remind me quickly: npm installed globally versus in a project, what was the difference in file structure and access?
It goes by where you start it. Run claude in a project folder and it reads your user settings, then that project's .claude/settings.json, then its settings.local.json; where two disagree, the more local wins. The way git finds the .git folder of wherever you are.
npm makes the same choice. npm install prettier puts it in the project's node_modules and records it in package.json, so it travels with the project. npm install -g prettier puts one copy on your machine, run from anywhere. Claude Code is like the global one; a project's .claude/settings.json is like its package.json, instructions the tool reads in that folder.
Then remind me what npx does.
It runs a package's command without installing it for good. npx create-next-app@latest downloads it, runs it, and that's it. And npx prettier finds the prettier in the project's node_modules and runs that, so it needn't be installed globally.
Wait. I thought npm only installs packages inside the Node.js server, in node_modules. So if you're saying npm install -g can install a package into the local bin directory, how is that possible? How is it installing outside the Node.js server instance and onto your computer directly? Or am I missing something?
That was loose. There's no Node server involved: npm has two places it installs to. Locally, a project's node_modules. Globally, Node's own folder for packages, lib/node_modules, with a in a bin folder on PATH so the shell can find the command. Both are npm's, chosen by -g.
I thought Claude would install the same way Bun does: its own folder with a bin, unlike Node.js.
Right, it does. npm puts global packages in its shared folder and links them into a shared bin. Bun keeps its own folder, ~/.bun. Claude Code does the same as Bun: its files in ~/.local/share/claude, and one link, ~/.local/bin/claude, on PATH. Delete the folder and it's gone.
Again about npx… explain this: "npx plugins add vercel/vercel-plugin".
Not Claude Code's /plugin at all. npx runs an npm package called plugins, and passes it add vercel/vercel-plugin. The same word, from a different world.
Like, where will things be stored and saved? I want to know what happens with the files. Give me the juicy behind-the-scenes, and why.
That depends on which plugins tool it is. Where did you see the command?
In Vercel's documentation.
Then plugins is an installer for plugins written in a format several coding agents share. vercel/vercel-plugin is a GitHub repository. The plugin adds Vercel's current docs to a session as skills, for Next.js, the AI SDK and the rest, because a model's training stops at a date and Vercel moves on.