Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 880 Bytes

express.md

File metadata and controls

53 lines (38 loc) · 880 Bytes

Setting up Express

Credentials

In the root of your project, create a .env file and add your OpenAI API key:

OPENAI_API_KEY=sk-...

Then install the dotenv package if you haven't already:

npm install dotenv --save
# or
yarn add dotenv

Install Beak.js for Express

npm install @beak/express --save
# or
yarn add @beak/express

Add the middleware

For example:

import express from "express";
import { beakHandler } from "@beakjs/express";
import dotenv from "dotenv";
dotenv.config();

const app = express();
const port = 3000;

app.use("/beak", beakHandler());

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

Configure Beak to use the Express backend

const App = () => {
  return <Beak baseUrl="/beak">... your app code goes here</Beak>;
};