02ENVIRONMENT SETUP

Environment Setup

Setting up your development environment and initializing the backend server with Express and LangChain.


What is LangChain?

Think of LangChain like a recipe for building smart apps that talks and thinks in natural language. In the old days, you'd hard-code every step of a program. LangChain lets you mix and match "blocks" (like kitchens with different tools) so you can whip up an AI application without reinventing the wheel each time.

LangChain Overview

1LLMs (Language Models)

What they are: Huge, pretrained text engines (e.g., OpenAI's GPT, Google's PaLM).

What they do: They "understand" and "write" human-like text when you give them prompts.

Analogy

Think of an LLM as your master chef - it knows tons of language and cuisines, but needs your instructions.

2Tools (APIs, Database, Files)

What they are: Connectors to outside services - weather APIs, search engines, databases, even your own CSV files.

What they do: They fetch data or perform tasks that the LLM alone can't do (like checking today's weather or querying your customer list).

Analogy

Tools are like pots, pans, and mixers in the kitchen. Your chef (LLM) uses them to get special ingredients or cook things just right.

3Chains (Combining Steps)

What they are: Predefined workflows that string LLM calls and Tools together in order.

What they do: Make multi-step processes easy: e.g., "Read a customer question, look up their order status in the database, draft a reply email."

Analogy

A chain in your recipe's step-by-step instructions. It tells the chef when to grab the whisk or preheat the oven, so every dish comes out perfect.

How It All Fits Together

You write a prompt

Find me today's weather in Mumbai

LangChain sends it to the LLM

to understand your intent

LLM says, "I need outside data,",

so LangChain invokes the Weather API tool.

The tool returns "31°C, Sunny,",

which the LLM wraps up into a friendly response.

Result:

Good afternoon! Right now in Mumbai it’s 31°C and sunny. Don’t forget your sunglasses!

🧠 Why Use LangChain?

Save Time

No need to glue together every API and prompt by hand.

Stay Organized

Recipes (chains) live in code so you can review, update, and share them easily.

Scale Up

Add new tools or swap in a different LLM without rewriting your whole app.

"Just like learning to cook, you’ll start with simple recipes. Over time you’ll look back—and thank yourself for mastering the basics. With LangChain’s blocks (LLMs, Tools, Chains), you’ll be mixing up powerful AI dishes in no time!"


Setting up the backend server

We will be creating the backend server using Express. Follow the following steps to setup:

Create a directory with the name server
mkdir youtube-rag && cd youtube-rag
 mkdir server
 cd server
Initialise a package.json file
npm init -y
Install the following packages
npm install express cors dotenv @langchain/core @langchain/community youtubei youtubei.js

Here we are using various packages, each has its own role:

  • express = A minimal and flexible Node.js web framework.
  • cors = Middleware to enable Cross-Origin Resource Sharing.
  • dotenv = Loads environment variables from a .env file.
  • @langchain/core = Foundational building blocks of LangChain.
  • @langchain/community = Community-supported integrations.
  • youtubei & youtubei.js = Wrappers for YouTube's internal API.
Create a basic server
import express from 'express';
import cors from 'cors';

const app = express();

app.use(express.json());

const corsOptions = {
  origin: 'http://localhost:5173',
  methods: ['GET', 'POST', 'PUT', 'DELETE'],
  allowedHeaders: ['Content-Type', 'Authorization']
};

app.use(cors(corsOptions));

app.use('/', (req, res) => {
  res.send('Server is Up and Running!!');
});

app.listen('8000', () => {
  console.log('Server Running on PORT 8000');
});

export default app;
Start the Server by Running
nodemon index.js

Note: nodemon will help restart the server on every small change we make.

⚙️Get Supabase API Key

Go to Supabase and follow these steps:

1. Create an Organization

Supabase Org

2. Get the API Key and Base URL

Supabase Credentials

Copy them in a .env file in the root of your server directory:

.env
SUPABASE_URL=YOUR_SUPABASE_URL
SUPABASE_API_KEY=YOUR_API_KEY

Final Setup

Once you are done with this, this is how your final server folder setup will look like:

server
node_modules
index.js
.env
package.json
package-lock.json
🥳

Congratulations!

You've successfully set up your first ExpressJS server.

⚙️ Next Steps

In the next section, we’ll:

  • Create and Configure the Tables for Supabase

If you want to know more about this, do checkout our video guide: