npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

labnocturne

v1.0.0

Published

JavaScript/Node.js client for Lab Nocturne Images API

Readme

Lab Nocturne Images - JavaScript/Node.js Client

JavaScript/Node.js client library for the Lab Nocturne Images API.

Installation

Due to npm's subdirectory limitations, install locally:

# Clone the repository
git clone https://github.com/jjenkins/labnocturne-image-client.git
cd labnocturne-image-client/javascript

# Install dependencies and link globally
npm install
npm link

# In your project directory
npm link labnocturne

Alternative: Use path dependency in your package.json:

{
  "dependencies": {
    "labnocturne": "file:../labnocturne-image-client/javascript"
  }
}

Requirements

  • Node.js 18.0.0+
  • form-data package (automatically installed)

Quick Start

import LabNocturneClient from 'labnocturne';

// Generate a test API key
const apiKey = await LabNocturneClient.generateTestKey();
console.log('API Key:', apiKey);

// Create client
const client = new LabNocturneClient(apiKey);

// Upload an image
const result = await client.upload('photo.jpg');
console.log('Image URL:', result.url);
console.log('Image ID:', result.id);

// List files
const files = await client.listFiles({ limit: 10 });
console.log('Total files:', files.pagination.total);

// Get usage stats
const stats = await client.getStats();
console.log(`Storage: ${stats.storage_used_mb.toFixed(2)} MB / ${stats.quota_mb} MB`);

// Delete a file
await client.deleteFile(result.id);
console.log('File deleted');

API Reference

new LabNocturneClient(apiKey, baseUrl)

Create a new client instance.

Parameters:

  • apiKey (string): Your API key
  • baseUrl (string, optional): Base URL for the API (default: https://images.labnocturne.com)

Methods

static async generateTestKey(baseUrl)

Generate a test API key for development.

Parameters:

  • baseUrl (string, optional): Base URL for the API

Returns: Promise - API key

Example:

const apiKey = await LabNocturneClient.generateTestKey();

async upload(filePath)

Upload an image file.

Parameters:

  • filePath (string): Path to the image file

Returns: Promise - Object with id, url, size, mime_type, created_at

Example:

const result = await client.upload('photo.jpg');
console.log(result.url);

async listFiles(options)

List uploaded files with pagination.

Parameters:

  • options (object, optional):
    • page (number): Page number (default: 1)
    • limit (number): Files per page (default: 50)
    • sort (string): Sort order - created_desc, created_asc, size_desc, size_asc, name_asc, name_desc

Returns: Promise - Object with files array and pagination info

Example:

const files = await client.listFiles({ page: 1, limit: 10, sort: 'size_desc' });
files.files.forEach(file => {
  console.log(`${file.id}: ${file.size} bytes`);
});

async getStats()

Get usage statistics for your account.

Returns: Promise - Object with storage_used_bytes, storage_used_mb, file_count, quota_bytes, quota_mb, usage_percent

Example:

const stats = await client.getStats();
console.log(`Using ${stats.usage_percent.toFixed(1)}% of quota`);

async deleteFile(imageId)

Delete an image (soft delete).

Parameters:

  • imageId (string): The image ID

Returns: Promise

Example:

await client.deleteFile('img_01jcd8x9k2n...');

TypeScript Support

This package includes TypeScript definitions. No additional types package needed.

import LabNocturneClient, { UploadResponse, StatsResponse } from 'labnocturne';

const client = new LabNocturneClient(apiKey);
const result: UploadResponse = await client.upload('photo.jpg');
const stats: StatsResponse = await client.getStats();

Error Handling

try {
  const result = await client.upload('photo.jpg');
  console.log('Success:', result.url);
} catch (error) {
  if (error.code === 'ENOENT') {
    console.error('File not found');
  } else {
    console.error('Upload failed:', error.message);
  }
}

Complete Example

import LabNocturneClient from 'labnocturne';

async function main() {
  try {
    // Generate test API key
    console.log('Generating test API key...');
    const apiKey = await LabNocturneClient.generateTestKey();
    console.log('API Key:', apiKey);
    console.log();

    // Create client
    const client = new LabNocturneClient(apiKey);

    // Upload an image
    console.log('Uploading image...');
    const upload = await client.upload('photo.jpg');
    console.log('Uploaded:', upload.url);
    console.log('Image ID:', upload.id);
    console.log('Size:', (upload.size / 1024).toFixed(2), 'KB');
    console.log();

    // List all files
    console.log('Listing files...');
    const files = await client.listFiles({ limit: 10 });
    console.log('Total files:', files.pagination.total);
    files.files.forEach(file => {
      console.log(`  - ${file.id}: ${(file.size / 1024).toFixed(2)} KB`);
    });
    console.log();

    // Get usage stats
    console.log('Usage statistics:');
    const stats = await client.getStats();
    console.log(`  Storage: ${stats.storage_used_mb.toFixed(2)} MB / ${stats.quota_mb} MB`);
    console.log(`  Files: ${stats.file_count}`);
    console.log(`  Usage: ${stats.usage_percent.toFixed(2)}%`);
    console.log();

    // Delete the uploaded file
    console.log('Deleting image...');
    await client.deleteFile(upload.id);
    console.log('Deleted successfully');

  } catch (error) {
    console.error('Error:', error.message);
  }
}

main();

Save as example.js and run:

node example.js

Browser Usage

For browser environments, you'll need to adapt the upload method as fs is not available:

// Browser-compatible upload using File object
async uploadFromBrowser(file) {
  const formData = new FormData();
  formData.append('file', file);

  const response = await fetch(`${this.baseUrl}/upload`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${this.apiKey}`
    },
    body: formData
  });

  if (!response.ok) {
    const error = await response.json();
    throw new Error(`Upload failed: ${error.error.message}`);
  }

  return await response.json();
}

License

MIT License - See LICENSE for details.

Links