exa-local-dev-loop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Exa Local Dev Loop

Exa本地开发循环

Overview

概述

Set up a fast, reproducible local development workflow for Exa.
为Exa搭建一个快速、可复现的本地开发工作流。

Prerequisites

前置条件

  • Completed
    exa-install-auth
    setup
  • Node.js 18+ with npm/pnpm
  • Code editor with TypeScript support
  • Git for version control
  • 已完成
    exa-install-auth
    配置
  • 安装有npm/pnpm的Node.js 18+版本
  • 支持TypeScript的代码编辑器
  • 用于版本控制的Git

Instructions

操作步骤

Step 1: Create Project Structure

步骤1:创建项目结构

my-exa-project/
├── src/
│   ├── exa/
│   │   ├── client.ts       # Exa client wrapper
│   │   ├── config.ts       # Configuration management
│   │   └── utils.ts        # Helper functions
│   └── index.ts
├── tests/
│   └── exa.test.ts
├── .env.local              # Local secrets (git-ignored)
├── .env.example            # Template for team
└── package.json
my-exa-project/
├── src/
│   ├── exa/
│   │   ├── client.ts       # Exa client wrapper
│   │   ├── config.ts       # Configuration management
│   │   └── utils.ts        # Helper functions
│   └── index.ts
├── tests/
│   └── exa.test.ts
├── .env.local              # Local secrets (git-ignored)
├── .env.example            # Template for team
└── package.json

Step 2: Configure Environment

步骤2:配置环境

bash
undefined
bash
undefined

Copy environment template

复制环境变量模板

cp .env.example .env.local
cp .env.example .env.local

Install dependencies

安装依赖

npm install
npm install

Start development server

启动开发服务器

npm run dev
undefined
npm run dev
undefined

Step 3: Setup Hot Reload

步骤3:配置热重载

json
{
  "scripts": {
    "dev": "tsx watch src/index.ts",
    "test": "vitest",
    "test:watch": "vitest --watch"
  }
}
json
{
  "scripts": {
    "dev": "tsx watch src/index.ts",
    "test": "vitest",
    "test:watch": "vitest --watch"
  }
}

Step 4: Configure Testing

步骤4:配置测试

typescript
import { describe, it, expect, vi } from 'vitest';
import { ExaClient } from '../src/exa/client';

describe('Exa Client', () => {
  it('should initialize with API key', () => {
    const client = new ExaClient({ apiKey: 'test-key' });
    expect(client).toBeDefined();
  });
});
typescript
import { describe, it, expect, vi } from 'vitest';
import { ExaClient } from '../src/exa/client';

describe('Exa Client', () => {
  it('should initialize with API key', () => {
    const client = new ExaClient({ apiKey: 'test-key' });
    expect(client).toBeDefined();
  });
});

Output

输出结果

  • Working development environment with hot reload
  • Configured test suite with mocking
  • Environment variable management
  • Fast iteration cycle for Exa development
  • 可正常运行且带有热重载功能的开发环境
  • 已配置好Mock功能的测试套件
  • 环境变量管理
  • 适用于Exa开发的快速迭代周期

Error Handling

错误处理

ErrorCauseSolution
Module not foundMissing dependencyRun
npm install
Port in useAnother processKill process or change port
Env not loadedMissing .env.localCopy from .env.example
Test timeoutSlow networkIncrease test timeout
错误原因解决方案
模块未找到缺少依赖执行
npm install
端口被占用有其他进程占用端口终止该进程或更换端口
环境变量未加载缺少.env.local文件从.env.example复制
测试超时网络缓慢延长测试超时时间

Examples

示例

Mock Exa Responses

Mock Exa响应

typescript
vi.mock('@exa/sdk', () => ({
  ExaClient: vi.fn().mockImplementation(() => ({
    // Mock methods here
  })),
}));
typescript
vi.mock('@exa/sdk', () => ({
  ExaClient: vi.fn().mockImplementation(() => ({
    // Mock methods here
  })),
}));

Debug Mode

调试模式

bash
undefined
bash
undefined

Enable verbose logging

启用详细日志

DEBUG=EXA=* npm run dev
undefined
DEBUG=EXA=* npm run dev
undefined

Resources

参考资源

Next Steps

后续步骤

See
exa-sdk-patterns
for production-ready code patterns.
如需查看生产环境可用的代码模式,请参考
exa-sdk-patterns