Next.js Discord

Discord Forum

Is there any way for using server-to-server communication?

Red wood ant posted this in #help-forum
Open in Discord
Red wood antOP
I'm glad to see you.
I have a problem that have been bothering me.
In this code, I can't use fetch to use ytdl-core library.
Therefore I have to find ways to use server-to-server communication.
Is there any way for using server-to-server communication?

2 Replies

import { NextResponse } from "next/server";
import ytdl from "ytdl-core";

export async function GET() {
  const musicStream = ytdl("");

  const data = new ReadableStream({
    start(controller) {
      musicStream.on("data", (chunk: Buffer) =>
        controller.enqueue(new Uint8Array(chunk))
      musicStream.on("end", () => controller.close());
      musicStream.on("error", (error: NodeJS.ErrnoException) =>
    cancel() {

  const filename = "example.mp4";

  return new NextResponse(data, {
    headers: {
      "content-disposition": `attachment; filename=${filename}`,
Red wood antOP
Oh, Thanks.
However I found different way to fix that before.
It is not using NextResponse, but using Response.
This is my code.
  try {
    if (url) {
      const stream = ytdl(`${url}`, { filter: 'audioonly', quality: 'highestaudio', format: 'mp3' })
      const response = new Response(stream);
      return response
    throw "no datas"
  } catch (e) {
    return NextResponse.json({ err: e }, { status: 500 })