node package manager


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 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.


  • node.js, tested with 0.4.1
  • OS X, version 10.5 or later (soon, any OS with a hosts file)
  • superuser access to your machine


$ npm install localhose

Module API

localhose = require( "localhose" )

Returns a global localhose object that keeps track of what domains are being rerouted.

localhose.set( host1, [host2], [etc] )

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
# </localhose>

The path of the host file can be specified using the hostsPath property of the localhose.constructor.prototype object.

localhose.unset( [host1], [host2], [etc] )

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

Command-line API

$ sudo localhose set host1 [host2] [etc]

Same as localhose.set, but for the command line.

$ sudo localhose unset [host1] [host2] [etc]

Same as localhose.unset, but for the command line.


For an example rerouting to your machine, see test.js. Otherwise, usage is basically like this:

// sudo node ./someFile.js
localhose = require( "localhose" )

// resolve "" and "" to
// note that you will be unable to use google while this is set.
localhose.set( "", "" ) // [ "", "" ]

// remove all domains, and revert the `hosts` file to its original state
localhose.unset( "" )


  • Add support for non-OS X systems if anyone's interested.


Copyright (c) 2011 Jed Schmidt. See LICENSE.txt for details.

Send any questions or comments here.