You can run this example with:
npx promptfoo@latest init --example config-node-package
cd config-node-packageThis example demonstrates using promptfoo from a Node.js script.
- Node.js ^20.20.0 or >=22.22.0 (Node.js 20 support ends July 30, 2026; Node.js 24 LTS recommended)
- API keys for LLM providers set as environment variables:
OPENAI_API_KEY- Get from OpenAI API keys pageANTHROPIC_API_KEY- Get from Anthropic Console (optional)
You can set these in a .env file:
OPENAI_API_KEY=sk-your-key-here
ANTHROPIC_API_KEY=sk-ant-your-key-here
- Install dependencies:
npm install- Execute the script:
node full-eval.jsThe script will:
- Run evaluations programmatically using the promptfoo Node.js API
- Save results to
output.json - Display evaluation metrics in the console
- Allow you to view detailed results with
promptfoo view