How to install Grunt

Grunt is basically a build / task manager written on top of NodeJS. Here are some common scenarios you would require grunt:
1) You have a project with SASS/ LESS files which need to be compiled to CSS files on the developers machine during development, For example whenever he saves a SASS file, you want it to be compiled to a CSS file automatically, for inclusion in your page. (grunt-contrib-sass)

2) When you save code on your machine during development, you want the browser to reload your page automatically (might seem like a small thing, but believe me this has saved me lots of time). (Live reload)

3) When a developer saves code on his machine, he wants a comprehensive list of JS errors / general best practice violations to be shown. (grunt-contrib-jshint)

4) You have a project with javascript files requiring minification, and generally generating a front end build seperately (in case you’re using say JAVA for your backend). (grunt-contrib-uglify)

5) You have a team of front end developers who’re working on the UI, and a team of backend developers working on the backend, you want the front end devs to use the backend REST API’s without having to compile & deploy code everytime on their own machines.
In case you were wondering, this isn’t possible with a typical web server setup because XHR isn’t allowed to be cross-domain by browser.
Grunt can setup a proxy for you redirecting XHR requests on your own system within the grunt connect server to another system! (grunt-contrib-proxy, grunt-contrib-connect)

Grunt Setup in local machine
You need to install node package manager inorder to use grunt.
Installation steps for node js
1) Download the Windows installer from the Official Nodes.js web site.
2) Run the installer (the package you downloaded in the previous step.)
3) Follow the prompts in the installer (Accept the license agreement, click the NEXT button and accept the default installation settings).
4) Restart your computer. (Note: You won’t be able to run Node.js® until you restart your computer.)

NodeJS is installed on Windows in the c:\Program Files\nodejs folder, but the npm modules are installed to the D:\Users\\AppData\Roaming\npm. The Windows installer for NodeJS does not add this folder to the PATH environment variable. So when you install new npm modules as global tools they will not be found.

To resolve this, you might need to add the node js path into environment variables. For Eg. My node js installed path is D:\Users\vandhana.jayaprakash\AppData\Roaming\npm. This needs to be added in environment variables like below.

Go to My computer -> Right Click and Properties -> Advanced System settings.
node environemnt
To see if Node is installed properly, open the Windows Command Prompt or a similar command line tool, and type node -v. This should print a version number, so you’ll see something like this v0.10.35.
Test NPM. To see if NPM is installed, type npm -v in Terminal. This should print NPM’s version number so you’ll see something like this 1.4.28


2 thoughts on “How to install Grunt

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s