Skip to main content

Installation

This guide covers installing LangChain.js and its dependencies. LangChain.js is distributed as npm packages and supports multiple JavaScript runtimes.

Prerequisites

Before installing LangChain.js, ensure you have:
1

Node.js 20.x or higher

LangChain.js requires Node.js version 20.x, 22.x, or 24.x.
# Check your Node.js version
node -v
If you need to manage multiple Node.js versions, consider using nvm (Node Version Manager).
2

Package Manager

Choose one of the following package managers:
  • npm (comes with Node.js)
  • pnpm (recommended for monorepos)
  • yarn

Installing LangChain

Install the main langchain package using your preferred package manager:
npm install langchain
The langchain package includes:
  • Core LangChain functionality
  • Agent implementations
  • Chains and memory systems
  • Integration with @langchain/core (automatically installed as a dependency)

Installing Core Packages

Depending on your use case, you may want to install additional core packages:

@langchain/core

The @langchain/core package contains core abstractions and interfaces. It’s automatically installed with langchain, but you can also use it standalone:
npm install @langchain/core

@langchain/community

Community-maintained integrations for various tools and services:
npm install @langchain/community

@langchain/textsplitters

Utilities for splitting text and documents:
npm install @langchain/textsplitters

Installing Model Providers

To use LLMs, you’ll need to install at least one model provider package. Here are the most popular options:

OpenAI

npm install @langchain/openai

Anthropic (Claude)

npm install @langchain/anthropic

Google Vertex AI

npm install @langchain/google-vertexai

Google Generative AI

npm install @langchain/google-genai

Other Providers

LangChain.js supports many other providers:
ProviderPackage
Mistral AI@langchain/mistralai
Cohere@langchain/cohere
Groq@langchain/groq
Ollama@langchain/ollama
AWS Bedrock@langchain/aws
Cerebras@langchain/cerebras
DeepSeek@langchain/deepseek
xAI@langchain/xai
See the complete list of integrations for all available providers.

Environment Setup

After installing packages, you’ll need to set up API keys for the services you plan to use.
1

Create a .env file

Create a .env file in your project root:
touch .env
2

Add your API keys

Add the API keys for your chosen providers:
.env
# OpenAI
OPENAI_API_KEY=your-openai-api-key

# Anthropic
ANTHROPIC_API_KEY=your-anthropic-api-key

# Google (for Vertex AI or Generative AI)
GOOGLE_API_KEY=your-google-api-key

# Other providers
MISTRAL_API_KEY=your-mistral-api-key
COHERE_API_KEY=your-cohere-api-key
GROQ_API_KEY=your-groq-api-key
3

Load environment variables

Install and configure dotenv to load your environment variables:
npm install dotenv
Then load it at the start of your application:
import "dotenv/config";
Never commit your .env file to version control. Add it to your .gitignore:
.gitignore
.env
.env.local

Verifying Installation

Create a simple test file to verify your installation:
test.ts
import "dotenv/config";
import { ChatOpenAI } from "@langchain/openai";

const model = new ChatOpenAI({
  model: "gpt-4o-mini",
  temperature: 0,
});

const response = await model.invoke("Hello! Can you hear me?");
console.log(response.content);
Run the test:
npx tsx test.ts
If everything is set up correctly, you should see a response from the model.

TypeScript Configuration

LangChain.js is written in TypeScript. For the best development experience, configure your tsconfig.json:
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "lib": ["ES2022"],
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "isolatedModules": true
  }
}
LangChain.js uses ES modules by default. Make sure your package.json includes "type": "module" if using Node.js.

Alternative Runtimes

Deno

LangChain.js works with Deno. Import packages from npm:
import { ChatOpenAI } from "npm:@langchain/openai";
import { ChatPromptTemplate } from "npm:@langchain/core/prompts";

// Your code here

Bun

Install packages normally with Bun’s package manager:
bun add langchain @langchain/openai

Browser

For browser environments, use a bundler like Webpack, Vite, or Rollup. Most LangChain functionality works in browsers, but some features (like file system access) are Node.js-specific.
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";

// Your browser-compatible code here
When using LangChain in browsers, never expose API keys in client-side code. Use a backend proxy to make API calls securely.

Next Steps

Now that you have LangChain.js installed:

Quickstart

Build your first LangChain application with a step-by-step guide

Learn Core Concepts

Understand the fundamental concepts behind LangChain

Browse Integrations

Explore all available model providers and integrations

API Reference

Dive into the complete API documentation

Build docs developers (and LLMs) love