You are viewing a post from electro kami classic - hello!

How To: Install node and the handlebars precompiler

Nodejs is a great tool and library that should be utilized in any large scale site – it’s got a lot of the benefits of JavaScript with some added usefullness of Memcache, AJAX, and the ability to use JavaScript libraries like the always delightful Handlebars.

nodejs server setup

Follow these steps to get a Handlebars node compiler setup on your local machine

Note: On Mac OSX, all of the following commands will be done via Terminal. For Windows users that use the Node installer, use the program “Node.js command prompt” that is added when you install node.

  1. install node
    • brew install node
    • If you don’t have homebrew – install it with ruby:
      • /usr/bin/ruby -e “$(curl -fsSkL”
    • Alternatively, you can also download the Node installer
  2. install npm
    • curl | sh
    • If you used the Node installer, you may most likely skip this step as npm will already be pre-installed (check with cmd “npm”)
  3. install handlebars
    • npm install handlebars -g
    • verify with ‘which handlebars’
  4. compile template
    • create a folder named “templates” and place your “*.handlebars” templates into this folder
    • now compile those templates
      • handlebars /path-to-template-folder/templates -f /path-to-template-js-file/template.js -m true

Congratulate yourself – you have now compiled your first handlebar template!