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

letter-generator-ai

v1.0.0

Published

Express middleware for generating high-quality letters for various purposes using OpenAI's GPT-4o model

Readme

Letter Generator

Powered by LetterGeneratorAI

A professional Express middleware for generating high-quality letters for various purposes using OpenAI's GPT-4o model. This package allows you to quickly create business, personal, formal, creative, and academic letters with customizable tones.

Features

  • 🚀 Generate 5 types of letters (business, personal, formal, creative, academic)
  • 🎭 16 different tones to choose from (professional, friendly, formal, etc.)
  • 📏 Adjustable letter length (short, medium, long)
  • 🔒 Built-in rate limiting for API protection
  • ✅ Input validation with clear error messages
  • 📚 Well-documented API for easy integration

Installation

npm install letter-generator-ai

Quick Start

const express = require('express');
const createLetterGenerator = require('letter-generator-ai');

const app = express();
const OPENAI_API_KEY = 'your-openai-api-key';

// Mount the letter generator middleware
app.use('/api/letters', createLetterGenerator(OPENAI_API_KEY, {
  maxRequestsPerHour: 20, // Optional: default is 10
  debug: false // Optional: enable debug logging
}));

app.listen(3000, () => {
  console.log('Letter generator server running on port 3000');
});

API Endpoints

GET /api/letters/options

Returns available letter types, contexts, and tones.

Example Response

{
  "letterTypes": {
    "business": {
      "description": "Professional business correspondence",
      "contexts": ["job application", "resignation", "proposal", "meeting request", "..."]
    },
    "personal": { "..." },
    "formal": { "..." },
    "creative": { "..." },
    "academic": { "..." }
  },
  "tones": ["professional", "friendly", "formal", "casual", "..."]
}

POST /api/letters/generate

Generates a letter based on the provided parameters.

Request Body

{
  "type": "business",
  "context": "job application",
  "tone": "professional",
  "sender": "John Doe",
  "recipient": "HR Department, ABC Company",
  "details": "Applying for Senior Developer position with 5 years of experience in React and Node.js",
  "length": "medium"
}

Parameters

| Parameter | Type | Required | Description | |------------|--------|----------|-----------------------------------------------| | type | string | Yes | Letter type (business, personal, etc.) | | context | string | Yes | Context for the letter (job application, etc.) | | tone | string | Yes | Tone of the letter (professional, friendly, etc.) | | sender | string | Yes | Name/details of the sender | | recipient | string | Yes | Name/details of the recipient | | details | string | No | Additional details for letter content | | length | string | No | Length of letter (short, medium, long) |

Example Response

{
  "success": true,
  "letter": "Dear HR Department, ABC Company,\n\nI am writing to express my interest in the Senior Developer position...",
  "metadata": {
    "type": "business",
    "context": "job application",
    "tone": "professional",
    "length": "medium",
    "timestamp": "2023-11-17T12:34:56.789Z"
  }
}

Error Handling

The API returns clear error messages with appropriate HTTP status codes.

{
  "success": false,
  "error": "Invalid letter type. Available types: business, personal, formal, creative, academic",
  "code": "VALIDATION_ERROR",
  "timestamp": "2023-11-17T12:34:56.789Z"
}

Configuration Options

When initializing the middleware, you can provide the following options:

| Option | Type | Default | Description | |---------------------|---------|---------|-------------------------------------------| | maxRequestsPerHour | number | 10 | Maximum requests per hour per IP address | | debug | boolean | false | Enable debug logging |

Examples

Creating a Business Proposal Letter

const axios = require('axios');

async function generateBusinessProposal() {
  try {
    const response = await axios.post('http://localhost:3000/api/letters/generate', {
      type: 'business',
      context: 'proposal',
      tone: 'professional',
      sender: 'ABC Technology Solutions',
      recipient: 'XYZ Corporation',
      details: 'Proposal for implementing a new CRM system with a budget of $50,000',
      length: 'long'
    });
    
    console.log(response.data.letter);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
}

generateBusinessProposal();

Creating a Personal Thank You Letter

const axios = require('axios');

async function generateThankYouLetter() {
  try {
    const response = await axios.post('http://localhost:3000/api/letters/generate', {
      type: 'personal',
      context: 'thank you',
      tone: 'sincere',
      sender: 'Sarah',
      recipient: 'Aunt Martha',
      details: 'Thanking for the birthday gift - a beautiful handmade quilt',
      length: 'short'
    });
    
    console.log(response.data.letter);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
}

generateThankYouLetter();

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Security

This package requires a valid OpenAI API key. Make sure to keep your API key secure and never expose it in your client-side code.