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

godaddy-dns

v1.3.0

Published

A Node.js script to programmatically update GoDaddy DNS records

Downloads

113

Readme

godaddy-dns

A Node.js script to programmatically update GoDaddy DNS records

npm version CircleCI JavaScript Style Guide


Introduction

This Node.js script allows you to programmatically update one or more GoDaddy DNS records inserting the public IP of the machine where the script is run.

Quick example:

godaddy-dns -c config.json

Requirements

This script requires Node.js (version >= 6.0.0) and a valid GoDaddy API key and secret. You can get register a new key on your GoDaddy developer page

Installation

To install the script globally you can use NPM:

npm install --global godaddy-dns

If you have the script already installed in your system, this command will update it to the latest available version.

After executing this command the script godaddy-dns will be globally available in your system. Give it a try with:

godaddy-dns -V

Binaries

From version 1.1.0, you can also install godaddy-dns by simply downloading the binary executable file for your operative system in the Releases section.

Configuration

The command needs a configuration file in order to be executed. The configuration file can be specified at runtime using the option --config, if not specfied the command will try to access the file .godaddy-dns.json in the home directory of the current user.

The configuration file contains a JSON object with the following fields:

  • apiKey: The API key for your GoDaddy account
  • secret: The API key secret for your GoDaddy account
  • domain: The domain for which to update the DNS records
  • records: An array of objects that defines the records to update. Every record object can define the following values:
  • name: (mandatory) the name of the record (e.g. "mysubdomain", "@" or "*")
  • type: (default "A") the type of entry for the record
  • ttl: (default 600) the TTL of the record in seconds (min value is 600)

You can define the DNS records in the records configuration also using a shorter syntax by just passing the name of the domain as a plain string (e.g. "mysubdomain"). If you have a single record wrapping it into an array is optional, you can simply pass it as a single string or object.

See config.json.sample for an example of how to structure your config.json.

Update multiple domains

If you need to update multiple domains you can use the option domain in the records array as in the following configuration example:

{
  "apiKey": "",
  "secret": "",
  "domain": "example.com",
  "records": [
    {"type": "A", "name": "mysubdomain", "ttl": 600},
    {"domain":"my-other-domain.com", "type": "A", "name": "subdomain2", "ttl": 600} //overrides main domain name (example.com)
  ]
}

In this example, everytime a new IP is detected the following domains will be updated:

  • mysubdomain.example.com
  • subdomain2.my-other-domain.com

Last IP cache

To avoid to send useless requests to the GoDaddy API (e.g. when the IP is not changed) the script stores the last public ip sent to GoDaddy in a cache file. This file is by default stored in the default OS temp folder with the name .lastip. You can use a custom location for this file with the option --ipFile. If you want to clear this cache (and force a new request to the GoDaddy API) you can simply delete this file.

Running the script continuously with Cron

One of the principal use cases why you might want to use this script (and actually my original motivation to create it) is to map a DNS record to a machine with a non-static IP. This way you can recreate your home-made DynamicDNS solution.

In this scenario you might want to add an entry to your Cron configuration as in the following example:

*/5 * * * * godaddy-dns > /var/log/godaddy-dns.log 2>&1

In this case the script will be executed every 5 minutes and the logs will be stored in /var/logs/godaddy-dns.log. Also note that in this example you will use the default configuration file location. If you want to specify a different location use the option --config.

Command line options

Usage: godaddy-dns [options]

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -c, --config [file]  specify the configuration file to use  (default "<user home folder>/.godaddy-dns.json")
    -i, --ipfile [file]  specify which file to use to store the last found ip (default "<user temp folder>/.lastip")

Programmatic usage

If you want to use the features of this module in a Node.js project:

const dns = require("godaddy-dns");

dns.getCurrentIp().then((currentIp)=>{
  console.log("Current ip",currentIp);

  dns.updateRecords(currentIp,{
    "apiKey": "",
    "secret": "",
    "domain": "example.com",
    "records": [
      {"type": "A", "name": "@", "ttl": 600}
    ]
  })
  .then(() => {
    console.log(`[${new Date()}] Successfully updated DNS records to ip ${currentIp}`)
  })
  .catch((err) => {
    if (err && err.message !== 'Nothing to update') {
      console.error(`[${new Date()}] ${err}`)
      process.exit(1)
    }
  });
});

Thanks @aandrulis for suggesting to expose this.

Bugs and improvements

If you find a bug or have an idea about how to improve this script you can open an issue or submit a pull request, it will definitely make you a better person! 😝

License

Licensed under MIT License. © Luciano Mammino.