Hose your hosts file for easier local web development
Localhose is a node.js module that provides a simple API for dynamically adding hosts to the
/etc/hosts file, to fool your web browser into thinking
anydomain.com points to your local machine. This makes web development easier, since the local build and production build can now use identical URLs.
WARNING: This software requires superuser access, and will temporarily overwrite your hosts file. If you do not understand what that means, it's probably not a good tool for you.
$ npm install localhose
Returns a global
localhose object that keeps track of what domains are being rerouted.
Adds one or more hosts to be routed to your local machine. The hosts are stored within the existing hosts file, like this:
# <localhose> # The following have been added temporarily by Localhose # For more information, see https://github.com/jed/localhose 127.0.0.1 yourdomain.com 127.0.0.1 yourdomain.net # </localhose>
The path of the host file can be specified using the
hostsPath property of the
Removes some or all of the hosts rerouted to your machine. If no arguments are specified, all currently hosts are unset. If no hosts remain after this is called, the
# <localhose> ... # </localhose> section of the current
hosts file is removed, leaving your file system as pristine as it was before.
Returns a list of domains currently being rerouted to
localhose.set, but for the command line.
localhose.unset, but for the command line.
For an example rerouting
nodejs.org to your machine, see test.js. Otherwise, usage is basically like this:
// sudo node ./someFile.js localhose = require( "localhose" ) // resolve "google.com" and "google.org" to 127.0.0.1. // note that you will be unable to use google while this is set. localhose.set( "google.com", "google.org" ) localhose.domains() // [ "google.com", "google.org" ] // remove all domains, and revert the `hosts` file to its original state localhose.unset( "google.com" )
Copyright (c) 2011 Jed Schmidt. See LICENSE.txt for details.
Send any questions or comments here.