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 🙏

© 2024 – Pkg Stats / Ryan Hefner

txt-domain-verification

v1.0.1

Published

A Node.js package for verifying domain ownership through customizable DNS TXT records, supporting both promise and callback-based asynchronous workflows.

Downloads

11

Readme

Domain Verification

This package provides tools for verifying domain ownership through DNS TXT records. It supports customizable verification string formats and offers both callback and promise-based asynchronous interfaces.

Key Features

  • Generate DNS TXT record verification strings with customizable formats.
  • Verify domain ownership by checking for specific DNS TXT records.
  • Supports both callback and promise-based asynchronous patterns.

Installation

Install the package using npm:

npm install txt-domain-verification

Usage

Generating a Verification Code

Generate a verification code with an optional custom format. By default, the format is {{businessName}}-domain-verification={{code}}.

const { generateVerificationCode } = require('txt-domain-verification');

generateVerificationCode('example.com', 'mybusiness', '{{businessName}}-verification={{code}}', (err, result) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(result.instructions);
});

Verifying Domain Ownership

Verify if a domain has the expected DNS TXT record.

const { verifyDomain } = require('txt-domain-verification');

verifyDomain('example.com', 'mybusiness-verification=123abc', (err, isVerified) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(isVerified ? 'Verification successful.' : 'Verification failed.');
});

API Reference

generateVerificationCode(domain, [businessName], [format], [callback])

Generates a verification code and instruction for a DNS TXT record.

  • domain: The domain to be verified.
  • businessName: (Optional) Your business name, can be omitted.
  • format: (Optional) Custom format string with placeholders {{businessName}} and {{code}}. If not provided, a default format will be used.
  • callback: (Optional) Use for a callback pattern. If not provided, a promise will be returned.

verifyDomain(domain, verificationString, [callback])

Verifies the domain ownership by checking DNS TXT records.

  • domain: The domain to verify.
  • verificationString: The exact verification string expected to be found in DNS TXT records.
  • callback: (Optional) Use for a callback pattern.

Examples

Using require in Node.js

const { generateVerificationCode, verifyDomain } = require('txt-domain-verification');

// Generate a verification code
generateVerificationCode('example.com', 'mybusiness', '{{businessName}}-verification={{code}}', (err, result) => {
  if (err) {
    console.error('Error generating verification code:', err);
    return;
  }
  console.log('Verification code generated:', result.instructions);
});

// Later, to verify the domain
verifyDomain('example.com', 'mybusiness-verification=123abc', (err, isVerified) => {
  if (err) {
    console.error('Error verifying domain:', err);
    return;
  }
  console.log(isVerified ? 'Verification successful.' : 'Verification failed.');
});

Using import in ES Modules

For environments that support ES Modules, you can import the package as follows:

import { generateVerificationCode, verifyDomain } from 'txt-domain-verification';

// Generate a verification code
generateVerificationCode('example.com', 'mybusiness', '{{businessName}}-verification={{code}}')
  .then(result => {
    console.log('Verification code generated:', result.instructions);
  })
  .catch(err => {
    console.error('Error generating verification code:', err);
  });

// Later, to verify the domain
verifyDomain('example.com', 'mybusiness-verification=123abc')
  .then(isVerified => {
    console.log(isVerified ? 'Verification successful.' : 'Verification failed.');
  })
  .catch(err => {
    console.error('Error verifying domain:', err);
  });

Testing

This package includes a Jest test suite to ensure functionality works as expected. To run the tests, first install the package's development dependencies:

npm install

Then run the test suite with:

npm test

Contributing

Contributions are welcome! Please open an issue or submit a pull request with any improvements.

License

This project is licensed under the CC BY-SA License.