# JavaScript SDK Quickstart

> Install the Copyleaks JavaScript SDK, authenticate, and submit your first scan in minutes with this step-by-step guide.

This guide will walk you through installing the official JavaScript SDK and running your first scan. In just a few minutes, you'll be able to easily use Copyleaks products directly from your JavaScript or TypeScript application.

Before you start, ensure you have the following:
- An active Copyleaks account. If you don't have one, **[sign up for free](https://api.copyleaks.com/signup)**.
- You can find your API key on the **[API Dashboard](https://api.copyleaks.com/dashboard)**.
## Get Started
<Steps>
  <Step title="Installation">
    First, install the official `plagiarism-checker` package from npm into your project.

    ```bash
    npm i plagiarism-checker
    ```
  </Step>

  <Step title="Quick Example: Scan Text">
    The following example shows how to authenticate and submit a simple string of text for a plagiarism scan using the SDK's data models.

    <Warning>
      Remember to replace the placeholder credentials and webhook URL with your actual values.
    </Warning>

    <CodeGroup>
    ```javascript title="scan.js" icon="square-js"
    const { Copyleaks, CopyleaksFileSubmissionModel } = require('plagiarism-checker');

    // --- Your Credentials ---
    const EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    const KEY = 'YOUR_API_KEY';
    const WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
    // --------------------

    async function main() {
      console.log('Authenticating...');
      const copyleaks = new Copyleaks();
      const authToken = await copyleaks.loginAsync(EMAIL_ADDRESS, KEY);
      console.log(' Login successful!');

      console.log('Submitting text for scanning...');
      const scanId = `${Date.now()}`; // Use a timestamp for a unique ID
      const textToScan = 'Hello world, this is a test.';
      const base64Content = Buffer.from(textToScan).toString('base64');
      
      const submission = new CopyleaksFileSubmissionModel(
        base64Content,
        'test.txt',
        {
          sandbox: true, // Turn on sandbox mode for testing
          webhooks: {
            status: WEBHOOK_URL
          }
        }
      );
      
      await copyleaks.submitFileAsync(authToken, scanId, submission);
      console.log(` Scan submitted successfully! Scan ID: ${scanId}`);
    }

    main().catch(err => console.error(err));
    ```
    ```typescript title="scan.ts" icon="code"
    import { 
      Copyleaks, 
      CopyleaksFileSubmissionModel,
      type CopyleaksAuthToken 
    } from 'plagiarism-checker';

    // --- Your Credentials ---
    const EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    const KEY = 'YOUR_API_KEY';
    const WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
    // --------------------

    async function main() {
      console.log('Authenticating...');
      const copyleaks = new Copyleaks();
      const authToken: CopyleaksAuthToken = await copyleaks.loginAsync(EMAIL_ADDRESS, KEY);
      console.log(' Login successful!');

      console.log('Submitting text for scanning...');
      const scanId = `${Date.now()}`; // Use a timestamp for a unique ID
      const textToScan = 'Hello world, this is a test.';
      const base64Content = Buffer.from(textToScan).toString('base64');

      const submission = new CopyleaksFileSubmissionModel(
        base64Content,
        'test.txt',
        {
          sandbox: true, // Turn on sandbox mode for testing
          webhooks: {
            status: WEBHOOK_URL
          }
        }
      );

      await copyleaks.submitFileAsync(authToken, scanId, submission);
      console.log(` Scan submitted successfully! Scan ID: ${scanId}`);
    }

    main().catch(err => console.error(err));
    ```
    </CodeGroup>
  </Step>

  <Step title="Understanding the Code">
    1.  **Login**: We authenticate with your email and API key to get a secure login token.
    2.  **Prepare Submission**: We encode a string to Base64 and create a new `CopyleaksFileSubmissionModel`. This model is the recommended way to structure your submission data.
    3.  **Configure & Submit**: We pass the submission model to `submitFileAsync`. The model itself contains the sandbox settings and the webhook URL where Copyleaks will send a notification when the scan is complete.
  </Step>
</Steps>

## Next Steps

<CardGroup cols={2}>
  <Card title="GitHub Repository" icon="github" href="https://github.com/Copyleaks/NodeJS-Plagiarism-Checker">Check the official Copyleaks NodeJS SDK repository on GitHub for installation and usage details.</Card>
  <Card title="NPM Package" icon="js" href="https://www.npmjs.com/package/plagiarism-checker">Install the official Copyleaks NodeJS package from NPM for easy integration.</Card>
</CardGroup>

<CardGroup cols={2}>
  <Card title="Check for Plagiarism" icon="magnifying-glass" href="/guides/authenticity/detect-plagiarism-text">
    Detect plagiarism in text documents using the Copyleaks API. Search billions of sources to find unoriginal content.
  </Card>
  <Card title="Detect AI-Generated Content" icon="robot" href="/guides/ai-detector/ai-text-detection">
    Detect AI-generated text via sync or async API calls. This guide covers sync detection, see the Authenticity API Guide for async.
  </Card>
  <Card title="Assess Grammar and Writing Quality" icon="spell-check" href="/guides/writing/check-grammar">
    Get writing and grammar suggestions via API. Authenticate, submit text, and access full details in the docs.
  </Card>
  <Card title="Moderate Text" icon="shield-halved" href="/guides/moderation/moderate-text">
    Scan and moderate text content for unsafe or policy-relevant material across 10+ categories.
  </Card>
</CardGroup>
