How to Create a Facebook Video Download API Using Node.js and facebook-dl NPM

1️⃣ Install the Package

First, install the facebook-dl package in your Node.js project.

npm i facebook-dl

2️⃣ Set Up an Express.js Server

Now, create a simple API using Express.js that allows users to download Facebook videos by providing a URL.

const express = require("express");
const Facebook = require("facebook-dl");

const app = express();
const port = 3000;
const api = new Facebook();

app.get("/download", async (req, res) => {
    const { url } = req.query; // Get video URL from query parameters

    if (!url) {
        return res.status(400).json({ error: "Please provide a Facebook video URL." });
    }

    try {
        const videoInfo = await api.fbdl(url);
        res.json(videoInfo);
    } catch (error) {
        res.status(500).json({ error: "Failed to fetch video details.", details: error.message });
    }
});

app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}`);
});

3️⃣ Start the Server

Once the server is running, you can test the API by opening the following URL in your browser or using Postman.

http://localhost:3000/download?url=YOUR_FACEBOOK_VIDEO_URL

Replace YOUR_FACEBOOK_VIDEO_URL with an actual Facebook video URL.

With this setup, you can now create your own Facebook video download API! 🚀📹 Leave your feedback in a comment! 💬

Leave a Reply

Your email address will not be published. Required fields are marked *