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/hostfile

v1.0.7

Published

API and CLI for querying and manipulating host files

Downloads

14

Readme

@godaddy/hostfile

API and CLI for querying and manipulating host files.

Build Status

Installation

First, an important note. By default, most operating systems protect your host file by restricting write permissions. You'll need to change the permissions on that file before you can use the API or CLI to modify the file. For example:

sudo chown %USER: /etc/hosts

API

To use the API, install as a dependency:

npm i --save @godaddy/hostfile

...then import:

const hostfile = require('@godaddy/hostfile');

The following methods are supported:

.point(hostEntries: Dictionary<string, string>): Promise<void>

Where hostEntries is an object mapping host names to IP addresses, point assigns each host to an address. If an address is set to null, any existing host file overrides for the host are commented out instead.

.pointHost(host: string, address: string): Promise<void>

Shortcut method for .point({ [host]: address }).

.pointLocal(host: string): Promise<void>

Shortcut method for .point({ [host]: '127.0.0.1' }).

.reset(host: string): Promise<void>

Shortcut method for .point({ [host]: null }).

.untilExit(hostEntries: Dictionary<string, string>): Promise<void>

Same as .point, except SIGTERM, SIGINT, and SIGHUP handlers are installed for the process, and before exit, each of the hosts are reset. This is useful if you're developing a local service, and you only want your host file pointing locally while the service is running.

.isLocal(host: string): Promise<bool>

Resolves to true if the host is pointing to 0.0.0.0, 127.0.0.1, ::1, or ::0.

.watch(): Observable<string>

Returns an Observable that emits events when the host file changes. This is just a wrapper around fs.watch; see the node documentation for more information.

CLI

To install the hostfile command-line:

npm i -g @godaddy/hostfile

The hostfile command can be used as follows:

hostfile query host <hosts>               # Lists active entries for one or most hosts. Supports * wildcards.
hostfile query address <addresses>        # Lists active entries pointing to one or more address
hostfile point <hosts> [to] <address>     # Assigns <address> to one or most hosts
hostfile reset <hosts>                    # Removes hostfile assignments for one or more hosts

Operating System Support

hostwriter only knows how to find the host file on MacOS, Linux, and Windows at this time. If you have a need for other OS's, let us know.