Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with domain name services


Domain names provide convenient and easy-to-remember aliases for IP addresses so that we can navigate to websites and backend servers. Domain name services are responsible for converting domain names such as http://www.coffeescript.org or http://www.google.com to actual IP addresses.

In the following recipe, we will see how to look up the IP address for a domain name and how to perform a reverse lookup for an IP address.

Retrieving the IP address for a domain name

In this section, we will demonstrate how to look up an IP address for a given domain name.

Getting ready

We will be using Node's built-in DNS module to perform our domain lookups. There is nothing additional to install to perform this task.

How to do it...

We can perform a lookup in the following manner:

  1. Import Node's dns module:

    dns = require 'dns'
  2. Create a function to execute the lookup() function:

    lookupIpAddress = (domainName, callback) ->
      dns.lookup domainName, (err, ipAddress) ->
        if err...