Skip to main content
The vij-sdk is a lightweight, framework-agnostic library that works in both browser and Node.js environments.

Requirements

  • Node.js 18+ (for Node.js environments)
  • Modern browser (for browser environments)
  • TypeScript 4+ (optional, for TypeScript projects)

Installation

Install vij-sdk using your preferred package manager:
npm install vij-sdk

Basic Setup

Browser Applications

For vanilla JavaScript, React, Vue, Svelte, or any browser-based framework:
// src/main.jsx or src/index.js
import { init } from "vij-sdk";

// Initialize VIJ before rendering your app
init({
  endpoint: "https://your-vij-admin.com/api/logs",
  appId: "my-react-app",
  environment: "production"
});

// Then render your app
ReactDOM.createRoot(document.getElementById('root')).render(<App />);

Node.js Applications

For Express, Fastify, or any Node.js backend:
// server.js or index.js
import express from "express";
import { init } from "vij-sdk";

// Initialize VIJ at the very top
init({
  endpoint: "https://your-vij-admin.com/api/logs",
  appId: "my-api-server",
  environment: "production"
});

const app = express();

// Your server code
app.listen(3000, () => {
  console.log("Server running on port 3000");
});

Next.js Applications

Next.js requires special handling for App Router vs Pages Router:
  • App Router
  • Pages Router
  • Server-Side (API Routes)
Create a client component for SDK initialization:
lib/vij.js
"use client";
import { init } from "vij-sdk";

if (typeof window !== "undefined") {
  init({
    endpoint: process.env.NEXT_PUBLIC_VIJ_ENDPOINT,
    appId: "my-nextjs-app",
    environment: process.env.NODE_ENV === "production" ? "production" : "development"
  });
}

export default function VijInit() {
  return null;
}
Then import in your root layout:
app/layout.js
import VijInit from "./lib/vij";

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <VijInit />
        {children}
      </body>
    </html>
  );
}
Add environment variable to .env.local:
NEXT_PUBLIC_VIJ_ENDPOINT=https://your-vij-admin.com/api/logs

TypeScript Setup

vij-sdk includes full TypeScript definitions out of the box. No additional @types package needed!
example.ts
import { init, captureException, captureMessage, type InitOptions } from "vij-sdk";

const options: InitOptions = {
  endpoint: "https://your-vij-admin.com/api/logs",
  appId: "my-ts-app",
  environment: "production",
  batch: true,
  maxBatchSize: 20
};

init(options);

// TypeScript will provide full IntelliSense
captureException(new Error("Test error"), { userId: 123 }, "error");
captureMessage("User logged in", { email: "user@example.com" }, "info");

Verification

After installation, verify that VIJ is working:
import { captureMessage } from "vij-sdk";

// Send a test message
captureMessage("VIJ SDK initialized successfully!", { test: true }, "info");
Check your VIJ Admin dashboard at /logs — you should see the test message appear within a few seconds.

Module Formats

vij-sdk is distributed in multiple formats for maximum compatibility:
  • ESM (dist/index.mjs) - Modern JavaScript modules
  • CommonJS (dist/index.cjs) - Legacy Node.js require()
  • TypeScript (dist/index.d.ts) - Type definitions
The package.json exports field ensures the correct format is used automatically.

Bundle Size

vij-sdk is designed to be lightweight:
  • Minified: ~8KB
  • Gzipped: ~3KB
  • Zero dependencies (except tslib for TypeScript helpers)
vij-sdk is tree-shakeable. If you only use certain functions, your bundler will exclude unused code.

Troubleshooting

Issue: Cannot find module 'vij-sdk'Solution:
  • Ensure you ran npm install vij-sdk
  • Check that node_modules/vij-sdk exists
  • Try deleting node_modules and running install again
  • For Yarn/PNPM, ensure the package is in your lock file
Issue: Errors not appearing in dashboardSolution:
  • Verify init() is called before any other code
  • Check that endpoint URL is correct and accessible
  • Look for CORS errors in browser console
  • Ensure your VIJ Admin instance is running
  • Check Network tab for failed POST requests to /api/logs
Issue: Type errors or missing IntelliSenseSolution:
  • Ensure TypeScript 4+ is installed
  • Check that node_modules/vij-sdk/dist/index.d.ts exists
  • Try restarting your IDE/TypeScript server
  • Verify moduleResolution in tsconfig.json is set to “bundler” or “node16”
Issue: ReferenceError: window is not definedSolution:
  • Wrap init() in typeof window !== "undefined" check
  • Use "use client" directive for App Router components
  • See Next.js setup examples above

Next Steps