Dependency Installation - JavaScript¶
This guide covers installing GraphBit and its dependencies in JavaScript/Node.js environments.
System Requirements¶
Node.js¶
Minimum: Node.js 16.0.0 or later
Recommended: Node.js 18.0.0 or later (LTS)
Check your version:
Installation: - macOS: brew install node - Windows: Download from https://nodejs.org or choco install nodejs - Linux: apt-get install nodejs npm or equivalent
npm¶
Included with Node.js.
Check version:
Update npm:
Operating System Support¶
GraphBit supports: - ✅ Linux (x86_64, aarch64) - ✅ macOS (x86_64, arm64/M1/M2) - ✅ Windows (x86_64)
Installing GraphBit¶
Step 1: Create Project¶
Step 2: Install GraphBit Package¶
Verify installation:
Expected output:
Step 3: Verify Native Module¶
The JavaScript bindings are built as native modules (.node files). During installation, the correct binary for your platform should be downloaded automatically.
Check installed binary:
# Linux/macOS
ls node_modules/@infinitibit_gmbh/graphbit/*.node
# Windows
dir node_modules\@infinitibit_gmbh\graphbit\*.node
If binary is missing:
Step 4: Test Installation¶
Create a test file test.js:
const { init, getSystemInfo } = require('@infinitibit_gmbh/graphbit');
init();
const info = getSystemInfo();
console.log('GraphBit initialized successfully!');
console.log('System info:', info);
Run it:
Expected output:
Installing TypeScript (Optional but Recommended)¶
Step 1: Install TypeScript¶
Step 2: Initialize TypeScript¶
This creates tsconfig.json. Update it:
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
Step 3: Create TypeScript Example¶
Create src/example.ts:
import { init, LlmConfig, LlmClient } from '@infinitibit_gmbh/graphbit';
async function main() {
init();
const config = LlmConfig.openai({
apiKey: process.env.OPENAI_API_KEY || 'test',
model: 'gpt-4o-mini'
});
const client = new LlmClient(config);
try {
const result = await client.complete('Hello, world!');
console.log('Response:', result);
} catch (error) {
console.error('Error:', error);
}
}
main();
Step 4: Run TypeScript Code¶
Installing Development Dependencies¶
TypeScript & Tooling¶
Testing Framework (Vitest)¶
Create vitest.config.ts:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'node',
testTimeout: 30000
}
});
Create test file src/example.test.ts:
import { describe, it, expect } from 'vitest';
import { init } from '@infinitibit_gmbh/graphbit';
describe('GraphBit', () => {
it('should initialize', () => {
expect(() => init()).not.toThrow();
});
});
Run tests:
Web Development (Optional)¶
If building a web API or frontend that uses GraphBit:
Create src/server.ts:
import express from 'express';
import { init, LlmConfig, LlmClient } from '@infinitibit_gmbh/graphbit';
const app = express();
app.use(express.json());
init();
app.post('/api/complete', async (req, res) => {
try {
const { prompt } = req.body;
const config = LlmConfig.openai({
apiKey: process.env.OPENAI_API_KEY
});
const client = new LlmClient(config);
const result = await client.complete(prompt);
res.json({ result });
} catch (error) {
res.status(500).json({
error: error instanceof Error ? error.message : 'Unknown error'
});
}
});
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
Environment Configuration¶
API Keys¶
Set environment variables for LLM providers:
Linux/macOS:
Windows (PowerShell):
Windows (CMD):
Using .env file (with dotenv package):
Create .env:
Load in your code:
Troubleshooting Installation¶
Error: Cannot find module 'infinitibit_gmbh/graphbit'¶
Cause: Package not installed
Solution:
Error: Native module failed to load¶
Cause: Binary not compatible with your Node.js version/platform
Solution:
# Check Node.js version
node --version # Must be >= 16.0.0
# Rebuild native module
npm rebuild @infinitibit_gmbh/graphbit
# Or reinstall
rm -rf node_modules/@infinitibit_gmbh/graphbit
npm install @infinitibit_gmbh/graphbit
Error: EACCES permission denied (on Linux/macOS)¶
Cause: npm needs elevated permissions
Solution (don't use sudo):
npm install --global-style @infinitibit_gmbh/graphbit
# or
npm install --no-save @infinitibit_gmbh/graphbit
Error: Different platform binary installed¶
Cause: Installing on Linux, then running on macOS/Windows (or vice versa)
Solution:
# Clear npm cache
npm cache clean --force
# Reinstall for current platform
npm install @infinitibit_gmbh/graphbit
Error: TypeScript files not found¶
Cause: TypeScript definitions not installed
Solution:
# Definitions are bundled with @infinitibit_gmbh/graphbit
# Ensure TypeScript is installed
npm install --save-dev typescript
# Clear cache and reinstall
npm cache clean --force
npm install
Monorepo Setup (Advanced)¶
If using GraphBit in a monorepo with workspaces:
package.json:
packages/api/package.json:
Installation:
Docker Installation¶
Dockerfile¶
FROM node:18-slim
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy application code
COPY src ./src
# Copy TypeScript config
COPY tsconfig.json .
# Build TypeScript
RUN npm run build
# Run application
CMD ["node", "dist/index.js"]
docker-compose.yml¶
version: '3.9'
services:
graphbit-app:
build: .
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- NODE_ENV=production
ports:
- "3000:3000"
Run:
Version Management¶
Check Installed Version¶
Update to Latest Version¶
Update to Specific Version¶
Lock Version¶
In package.json:
Or use lock file:
Performance Optimization¶
Native Module Caching¶
GraphBit caches compiled bindings. For CI/CD:
# Restore from cache before install
npm ci
# Build/test
npm run build
# Cache node_modules for next run
Memory Optimization¶
For resource-constrained environments:
package.json:
Next Steps¶
After installation:
- Read the Quick Start: JavaScript Getting Started
- Explore Examples: Examples in Repository
- API Reference: JavaScript API Reference
- Learn Architecture: Architecture Guide
Getting Help¶
- Installation issues: Check Debugging Guide
- API questions: See JavaScript API Reference
- Examples: Check Examples Directory
- GitHub Issues: https://github.com/InfinitiBit/graphbit/issues