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

@fin.cx/opendata

v1.4.0

Published

A TypeScript library for accessing, managing, and updating open business data, focused on German companies and integrating with MongoDB.

Downloads

192

Readme

@fin.cx/opendata

A TypeScript-based library for accessing and managing open business data, specifically for German companies.

Install

To install the @fin.cx/opendata package, you can use npm or yarn as your package manager. Here's how you can do it:

Using npm:

npm install @fin.cx/opendata

Using yarn:

yarn add @fin.cx/opendata

Usage

The @fin.cx/opendata package provides a comprehensive set of functionalities for handling open business data, focusing on German business data. Let's explore the detailed capabilities of this library through extensive examples and instructions.

Setting Up the Environment

First, make sure you've set up the necessary environment variables for MongoDB. You will need the following environment variables:

  • MONGODB_URL: The URL for your MongoDB instance.
  • MONGODB_NAME: The name of the database to use.
  • MONGODB_USER: A valid username for accessing the database.
  • MONGODB_PASS: The password associated with the MongoDB user.

These variables can be configured in a .env file or managed through a specific service used for secure environment variables handling.

Importing and Initializing the Library

To start working with the library, import the necessary classes and initialize the OpenData class.

import { OpenData } from '@fin.cx/opendata';

const initializeOpenData = async () => {
  const openData = new OpenData();
  
  try {
    await openData.start();
    console.log('OpenData instance has started successfully.');
    
    // Example usage:
    await createAndManageBusinessRecords(openData);

  } catch (error) {
    console.error('Error starting OpenData:', error);
  } finally {
    await openData.stop();
    console.log('OpenData instance has stopped.');
  }
};

initializeOpenData();

Managing Business Records

The BusinessRecord class represents a company's data. Let's explore how you can create, retrieve, update, and manage these records.

Creating a New BusinessRecord

Creating a new business record involves instantiating the BusinessRecord class and setting the relevant properties.

import { BusinessRecord } from '@fin.cx/opendata';

const createBusinessRecord = async (openData: OpenData) => {
  const businessRecord = new openData.CBusinessRecord();
  
  businessRecord.data = {
    name: "Tech Innovations GmbH",
    address: "Tech Park 42",
    postalCode: "80333",
    city: "Munich",
    country: "Germany",
    phone: "+49 89 123456",
    email: "[email protected]",
    website: "https://techinnovations.de",
    businessType: "GmbH",
    registrationNumber: "HRB 654321",
    registrationCourt: "Munich",
    legalForm: "GmbH",
    managingDirectors: ["Alice Müller", "Bob Schmidt"],
    foundingDate: new Date("2020-01-01").toISOString(),
    capital: "100,000 EUR",
    purpose: "Developing innovative tech solutions",
    lastUpdate: new Date().toISOString()
  };

  await businessRecord.save();
  console.log('BusinessRecord saved:', businessRecord);
};

Retrieving Business Records

You can retrieve existing business records by querying the database using various data fields.

const retrieveBusinessRecords = async (openData: OpenData) => {
  const records = await openData.db
    .collection<BusinessRecord>('businessrecords')
    .find({ city: "Munich" })
    .toArray();

  console.log('Found Business Records:', records);
};

Updating Existing Records

To update an existing BusinessRecord, you retrieve the record, modify its data, and save it again.

const updateBusinessRecord = async (openData: OpenData, recordId: string) => {
  const businessRecord = await openData.CBusinessRecord.getInstance(recordId);
  if (businessRecord) {
    businessRecord.data.phone = "+49 89 987654";
    businessRecord.data.lastUpdate = new Date().toISOString();

    await businessRecord.save();
    console.log('BusinessRecord updated:', businessRecord);
  } else {
    console.log('BusinessRecord not found for id:', recordId);
  }
};

Deleting a Business Record

You can delete a business record using its unique identifier.

const deleteBusinessRecord = async (openData: OpenData, recordId: string) => {
  const businessRecord = await openData.CBusinessRecord.getInstance(recordId);
  if (businessRecord) {
    await businessRecord.delete();
    console.log(`BusinessRecord with id ${recordId} deleted successfully.`);
  } else {
    console.log('No record found for the provided id:', recordId);
  }
};

Updating German Business Data

The package includes functionalities to keep your business data up-to-date by downloading from official German open data repositories.

const updateGermanBusinessData = async (openData: OpenData) => {
  try {
    await openData.germanBusinesses.update();
    console.log('German business data has been updated successfully.');
  } catch (error) {
    console.error('Error updating German business data:', error);
  }
};

This function fetches the latest open data regarding German companies, processes it, and updates your local database.

Detailed Class Insights

OpenData Class

The OpenData class serves as the core of the library, initializing necessary components and controlling data flows:

  • db: Represents the connection to your MongoDB database.
  • germanBusinesses: An instance handling specific operations related to German business data updates.
class OpenData {
  db: plugins.smartdata.SmartdataDb;
  germanBusinesses: GermanBusinessData;

  private serviceQenv = new plugins.qenv.Qenv(paths.packageDir, paths.nogitDir);

  public async start() {
    // Database initialization logic
  }

  public async stop() {
    // Cleanup logic
  }
}

GermanBusinessData Class

This class deals specifically with German company data — fetching, processing, and updating local databases consistently with official German data sources.

class GermanBusinessData {
  public async start() {
    await this.update();
  }

  public async update() {
    // Logic for updating business data using import streams and parsing JSON lines.
  }
}

Ensuring Data Accuracy and Integrity

When working with business data, ensuring integrity and accuracy is crucial. Each record should be checked for validity before being saved or updated, minimizing inconsistencies. Moreover, robust error handling is essential in every step, from data retrieval to database operations, particularly when dealing with external data sources.

The @fin.cx/opendata module provides an extensive toolset for accessing and managing business data, particularly for companies based in Germany. Its functionalities include creating, updating, retrieving, and deleting business records, as well as keeping them current with the latest open data releases. This makes it an invaluable asset for developers aiming to integrate open data seamlessly into their systems, ensuring robust data management capabilities within their applications.

Happy exploring and integrating open data into your projects! undefined