exa-local-dev-loop
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExa Local Dev Loop
Exa本地开发循环
Overview
概述
Set up a fast, reproducible local development workflow for Exa.
为Exa搭建一个快速、可复现的本地开发工作流。
Prerequisites
前置条件
- Completed setup
exa-install-auth - 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.jsonmy-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.jsonStep 2: Configure Environment
步骤2:配置环境
bash
undefinedbash
undefinedCopy environment template
复制环境变量模板
cp .env.example .env.local
cp .env.example .env.local
Install dependencies
安装依赖
npm install
npm install
Start development server
启动开发服务器
npm run dev
undefinednpm run dev
undefinedStep 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
错误处理
| Error | Cause | Solution |
|---|---|---|
| Module not found | Missing dependency | Run |
| Port in use | Another process | Kill process or change port |
| Env not loaded | Missing .env.local | Copy from .env.example |
| Test timeout | Slow network | Increase test timeout |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 模块未找到 | 缺少依赖 | 执行 |
| 端口被占用 | 有其他进程占用端口 | 终止该进程或更换端口 |
| 环境变量未加载 | 缺少.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
undefinedbash
undefinedEnable verbose logging
启用详细日志
DEBUG=EXA=* npm run dev
undefinedDEBUG=EXA=* npm run dev
undefinedResources
参考资源
Next Steps
后续步骤
See for production-ready code patterns.
exa-sdk-patterns如需查看生产环境可用的代码模式,请参考。
exa-sdk-patterns