ACME Client for Node.js

5.4.0 · active · verified Tue Apr 21

acme-client is a simple and unopinionated Node.js library designed to interact with ACME (Automatic Certificate Management Environment) APIs, such as those provided by Let's Encrypt, Buypass, Google, and ZeroSSL. It adheres to RFC 8555 for ACME protocol communication. The current stable version is 5.4.0, requiring Node.js >= 16.0.0. The library primarily focuses on certificate management tasks, including account registration, order processing, and challenge fulfillment, supporting both RSA and ECDSA keys through native Node.js cryptography. It differentiates itself by being unopinionated and providing direct control over the ACME workflow, rather than an 'auto-mode' by default (though auto mode is available), and ships with TypeScript types for improved developer experience. While major versions have specific Node.js requirements, the project appears to release updates as needed, rather than on a fixed cadence.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the ACME client, create a new private key for the ACME account, and register or retrieve an ACME account from the Let's Encrypt staging environment.

import { Client, directory } from 'acme-client';
import { createPrivateKey } from 'crypto';

async function runAcmeClient() {
    // In a real application, load this from a secure source or generate it once
    const accountPrivateKey = createPrivateKey({
        type: 'rsa',
        modulusLength: 2048,
        publicKeyEncoding: {
            type: 'spki',
            format: 'pem'
        },
        privateKeyEncoding: {
            type: 'pkcs8',
            format: 'pem'
        }
    }).export({ type: 'pkcs8', format: 'pem' }).toString();

    console.log('Using account private key (truncated):', accountPrivateKey.substring(0, 50) + '...');

    const client = new Client({
        directoryUrl: directory.letsencrypt.staging,
        accountKey: accountPrivateKey,
    });

    console.log('ACME client initialized with Let\'s Encrypt staging directory.');

    // Example: Register a new ACME account or get existing one
    const account = await client.createAccount({
        termsOfServiceAgreed: true,
        contact: ['mailto:test@example.com'],
    });

    console.log('ACME account registered/fetched:', account);

    const accountUrl = client.getAccountUrl();
    console.log('Account URL:', accountUrl);

    // In a real scenario, you'd now proceed to create an order, generate a CSR, and fulfill challenges.
    // This quickstart only covers client initialization and account registration.
}

runAcmeClient().catch(console.error);

view raw JSON →