---
title: "JavaScript SDK Examples"
description: "Complete examples using the TraceRTM JavaScript SDK"
keywords: [javascript, sdk, examples, code samples, tutorials]
---

# JavaScript SDK Examples

Complete examples demonstrating TraceRTM JavaScript SDK usage.

## Complete Workflow Example

```javascript
import { TraceRTM } from '@tracertm/sdk';

async function createTraceabilityMatrix() {
  const client = new TraceRTM({
    apiKey: process.env.TRACERTM_API_KEY
  });

  // Create project
  const project = await client.projects.create({
    name: 'Authentication System',
    description: 'OAuth 2.0 implementation'
  });

  // Create requirements
  const req1 = await client.items.create({
    title: 'OAuth 2.0 Support',
    view: 'requirements',
    status: 'draft',
    metadata: { component: 'auth-service' }
  });

  const req2 = await client.items.create({
    title: 'JWT Token Validation',
    view: 'requirements',
    status: 'draft'
  });

  // Create test cases
  const test1 = await client.items.create({
    title: 'OAuth Flow Test',
    view: 'test-cases',
    status: 'draft'
  });

  // Create links
  await client.links.create({
    sourceId: req1.id,
    targetId: test1.id,
    linkType: 'verified_by'
  });

  // Transition items
  await client.items.transition(req1.id, {
    toStatus: 'active',
    comment: 'Requirements finalized'
  });

  console.log('Traceability matrix created!');
}

createTraceabilityMatrix().catch(console.error);
```

## Impact Analysis Example

```javascript
const impact = await client.analysis.impact({
  itemId: 'item_req_001',
  projectId: 'proj_123'
});

console.log(`Affects ${impact.totalAffected} items:`);
impact.affectedItems.forEach(item => {
  console.log(`  - ${item.title} (depth: ${item.depth})`);
});
```

## Error Handling Example

```javascript
import { NotFoundError, RateLimitError } from '@tracertm/sdk';

async function safeOperation(client, itemId) {
  try {
    const item = await client.items.get(itemId);
    await client.items.transition(itemId, { toStatus: 'active' });
    console.log('Operation successful');
  } catch (error) {
    if (error instanceof NotFoundError) {
      console.log('Item not found');
    } else if (error instanceof RateLimitError) {
      console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
      await sleep(error.retryAfter * 1000);
      return safeOperation(client, itemId);
    } else {
      console.error('Unexpected error:', error);
    }
  }
}
```

## Related Documentation

- [Quickstart](./02-quickstart) - Get started
- [Authentication](./03-authentication) - Auth setup
- [Artifacts](./04-artifacts) - Item operations
