This guide will help you install Harp. You’ll create and serve a simple project in
development mode, where preprocessing occurs automatically, and then in
production mode, where the preprocessed output is cached for better performance.
Install the Harp Web Server
On OS X and Linux
Access the command prompt using the Terminal application. On OS X, it’s located in Applications → Utilities → Terminal. On Ubuntu, find it in Applications → Terminal. Then, run the following command:
sudo npm install -g harp
If you are using Windows, NodeJS will have come with the Node.js Command Prompt application. Now, to install Harp via npm, type in:
npm install -g harp
Create an Application
Harp will serve something as simple as an
index.html. But, because Harp has built-in preprocessing, you can create HTML with a templating language just as easily. Create an
index.jadefile instead. To do this using the command line, run the following:
mkdir hello-world cd hello-world echo h1 Hello World >> index.jade
This will make a
hello-world/directory for your Harp app. Then, inside that directory, an
index.jadefile is created that will be served as
Start the web server
Fire up the Harp web server on the default port,
harp server --port 9000
Visiting localhost:9000 will now show the following:
Compile the project
Optionally to running as a web server you can compile to be run with a webserver of your choice. Harp makes for a great static site generator.
Putting Harp in Production
This is all you need to put a Harp application into production. In production mode, Harp will cache the preprocessed output—in this case, from
index.jade—to serve the files as quickly as possible. Always use this
productionflag when putting Harp in production:
NODE_ENV=production sudo harp server --port 80
You don’t need to manually run Harp in production to get your project online, however. The easiest way to get started is to use the Harp Platform, which lets you create and collaborate on Harp apps right in your Dropbox.
This is just a taste of what Harp can do for you. For example, the default Harp application also includes a
.less file that is automatically served as
.css. Being able to change the CSS just by editing the LESS file—no configuration necessary—makes the default app a good starting point for your own project; read more about initializing the default Harp app.