Language Setup Guide

JavaScript setup

Requirements

To use the UpRock API with JavaScript, you need Node.js 18 or higher and npm (Node package manager).

Initialize Your Project

If starting a new project, create a package.json file:

npm init -y

This creates a default package.json with basic project information.

Install Required Dependencies

npm install axios dotenv

Dependencies installed:

  • axios - Promise-based HTTP client for making API requests
  • dotenv - Loads environment variables from .env files

Configure Environment Variables

Ensure you have set up your environment variables as described in the get your API keys guide. Your .env file should contain:

UPROCK_API_KEY=your-api-key-here
# UPROCK_BASE_URL is optional - defaults to https://edge.uprock.com

Never commit your .env file to version control. Add it to .gitignore.

Verify Your Setup

Create a file named test-setup.js and run it to verify your setup:

test-setup.js
require('dotenv').config();  // Load environment variables from .env file
const axios = require('axios');

// Get configuration
const apiKey = process.env.UPROCK_API_KEY;
const baseUrl = process.env.UPROCK_BASE_URL || 'https://edge.uprock.com';

// Validate API key is set
if (!apiKey) {
  console.error('Error: UPROCK_API_KEY not set');
  process.exit(1);
}

// Test API connection
axios.get(`${baseUrl}/crawl/v1/health`, {
  headers: { Authorization: `Bearer ${apiKey}` }
})
.then(() => {
  console.log('✓ Setup verified - Ready to use UpRock Crawl API');
})
.catch(err => {
  const statusCode = err.response?.status || 'unknown';
  console.error(`✗ Setup failed with status code: ${statusCode}`);
  if (err.message) {
    console.error(`Error message: ${err.message}`);
  }
  process.exit(1);
});

Run the verification script:

node test-setup.js

First, add "type": "module" to your package.json:

package.json
{
  "type": "module",
  "dependencies": {
    "axios": "^1.0.0",
    "dotenv": "^16.0.0"
  }
}

Then create your verification script:

test-setup.js
import 'dotenv/config';
import axios from 'axios';

// Get configuration
const apiKey = process.env.UPROCK_API_KEY;
const baseUrl = process.env.UPROCK_BASE_URL || 'https://edge.uprock.com';

// Validate API key is set
if (!apiKey) {
  console.error('Error: UPROCK_API_KEY not set');
  process.exit(1);
}

// Test API connection
try {
  await axios.get(`${baseUrl}/crawl/v1/health`, {
    headers: { Authorization: `Bearer ${apiKey}` }
  });
  console.log('✓ Setup verified - Ready to use UpRock Crawl API');
} catch (err) {
  const statusCode = err.response?.status || 'unknown';
  console.error(`✗ Setup failed with status code: ${statusCode}`);
  if (err.message) {
    console.error(`Error message: ${err.message}`);
  }
  process.exit(1);
}

Run the verification script:

node test-setup.js

Expected Output

✓ Setup verified - Ready to use UpRock Crawl API

Common failure codes:

  • 401 - Invalid or missing API key
  • 403 - Inactive plan or insufficient permissions
  • 404 - Incorrect base URL

Troubleshooting

Below are solutions to common setup issues. If these don't resolve your problem, reach out to support@uprock.com.

API Key Not Found

Verify your .env file is in the project root directory and the variable name is exactly UPROCK_API_KEY.

Connection Errors

If behind a corporate proxy, configure the HTTPS_PROXY environment variable as described in the get your API keys guide.

On this page