Skip to main content

Setup and Installation


To get started, install LangChain with the following command:

npm install -S langchain

We currently support LangChain on Node.js 16, 18, and 19. Go here to vote on the next environment we should support.

Node.js 16

If you are running this on Node.js 16, either:

  • run your application with NODE_OPTIONS='--experimental-fetch' node ..., or
  • install node-fetch and follow the instructions here

If you are running this on Node.js 18 or 19, you do not need to do anything.


If you are using TypeScript we suggest updating your tsconfig.json to include the following:

"compilerOptions": {
"target": "ES2020", // or higher
"module": "nodenext",

Loading the library

ESM in Node.js

LangChain is an ESM library currently targeting Node.js environments. To use it, you will need to use the import syntax, inside a project with type: module in its package.json.

import { OpenAI } from "langchain";

CommonJS in Node.js

If your project is using CommonJS, you can use LangChain only with the dynamic import() syntax.

const { OpenAI } = await import("langchain");

If you're using TypeScript in a CommonJS project, you'll need to add the following to your tsconfig.json:

"compilerOptions": {
"moduleResolution": "node16",

Other environments

LangChain currently supports only Node.js-based environments. This includes Vercel Serverless functions (but not Edge functions), as well as other serverless environments, like AWS Lambda and Google Cloud Functions.

We currently do not support running LangChain in the browser. We are listening to the community on additional environments that we should support. Go here to vote and discuss the next environments we should support.

Please see Deployment for more information on deploying LangChain applications.