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 🙏

© 2026 – Pkg Stats / Ryan Hefner

groq-module

v1.0.2

Published

Ein einfaches Groq Node.js Modul

Readme

groq-module

A lightweight Node.js module for interacting with the Groq API. Easily send messages to AI models, manage conversation history, configure response formats, and process structured JSON responses with a simple interface.

Features

  • Simple integration with the Groq API
  • Support for multiple Groq models
  • Automatic language detection
  • Configurable response language
  • Optional plain-text response mode
  • JSON and JSON Schema response support
  • Conversation history management
  • Custom API key support
  • Environment variable support

Installation

npm install groq-module

For environment variable management, you can optionally install dotenv:

npm install dotenv

Configuration

Create a .env file in your project root:

GROQ_API_KEY=your_groq_api_key

You can obtain an API key from the Groq Console.

Usage

Import the askGroq function:

import { askGroq } from "groq-module";

Basic Example

const response = await askGroq("Hello, how are you?");

console.log(response);

The module automatically detects the language of the user's message and responds in the same language.

Custom Model

const response = await askGroq(
    "Explain how APIs work.",
    {
        model: "openai/gpt-oss-120b"
    }
);

console.log(response);

Custom Response Language

const response = await askGroq(
    "Hello!",
    {
        lang: "German"
    }
);

Plain Text Mode

Plain-text responses are enabled by default when no response format is specified.

const response = await askGroq(
    "Explain JavaScript.",
    {
        plainText: true
    }
);

JSON Responses

Request structured JSON responses using the responseFormat option:

const response = await askGroq(
    "Generate information about a fictional user.",
    {
        plainText: false,
        responseFormat: {
            type: "json_object"
        }
    }
);

console.log(response);

JSON responses are automatically parsed into JavaScript objects.

Conversation History

Maintain conversations by passing previous messages through the chat option.

const [answer, chat] = await askGroq(
    "My name is John.",
    {
        returnGroqChat: true
    }
);

console.log(answer);

const [nextAnswer, updatedChat] = await askGroq(
    "What is my name?",
    {
        chat,
        returnGroqChat: true
    }
);

console.log(nextAnswer);

Custom API Key

You can provide a custom API key instead of using the environment variable:

const response = await askGroq(
    "Hello!",
    {
        apiKey: "your_groq_api_key"
    }
);

API Reference

askGroq(messages, options)

Sends a request to the Groq Chat Completions API.

| Parameter | Type | Default | Description | |---|---|---|---| | messages | string \| Array | Required | User message or array of messages | | apiKey | string \| null | null | Custom Groq API key | | model | string | "openai/gpt-oss-120b" | Groq model identifier | | responseFormat | object \| null | null | Requested response format | | lang | string \| null | null | Preferred response language | | plainText | boolean | true | Requests plain-text responses | | returnGroqChat | boolean | false | Returns the updated conversation history | | chat | Array | [] | Previous conversation messages |

Return Values

By default, askGroq() returns the assistant response.

When returnGroqChat is enabled, it returns:

[
    answer,
    updatedChat
]

When JSON response formatting is enabled, the answer is automatically parsed into a JavaScript object.

Error Handling

The module throws errors when requests fail or invalid parameters are provided.

try {
    const response = await askGroq("Hello!");

    console.log(response);

} catch (error) {
    console.error("Groq API Error:", error.message);
}

Requirements

  • Node.js 18 or newer
  • A valid Groq API key
  • Internet connection

License

MIT License