gruntjs Getting started with gruntjs Installing Grunt



Grunt requires Node.js and npm to be installed. If you don’t have Node.js and/or npm installed on your machine, go to and download the installer or package for your operating system.

First-time install

If you're installing Grunt for the first time, you'll first have to install the Grunt command-line interface package grunt-cli globally.

npm install -g grunt-cli

This installs the command-line interface for Grunt globally so you can run the local version of Grunt in your project.

You can verify that you have grunt-cli package installed by running the following command:

grunt --version

This should print at least the current version of your grunt-cli package.

Installing Grunt in your project

After you have grunt-cli up and running, you can install the actual grunt task runner and your first Grunt package grunt-contrib-jshint:

npm install grunt --save-dev
npm install grunt-contrib-jshint --save-dev

This downloads the packages from NPM package manager and saves them as devDependencies to your package.json file.


Next you need a Gruntfile.js in your project root that acts as a config file for Grunt tasks:

module.exports = function(grunt) {

        jshint: {
            files: ['Gruntfile.js'],


    grunt.registerTask('default', ['jshint']);

This file does three things:

  1. It tells Grunt to load the grunt-contrib-jshint task from NPM package
  2. It advices the jshint task to run against the file Gruntfile.js
  3. It creates a Grunt task named default that runs the jshint task

Running Grunt

After you have set up your project you can run the default task of Grunt by calling:


This fires up grunt-cli that runs the local grunt which looks for a Grunt task named default which is configured to run the task called jshint.