We will use the NPM to install Karma and other dependencies. Let's start creating a practice folder called practice-karma and initializing our project. Run the following command:
$ mkdir practice-karma
$ cd practice-karma
$ npm init
We use npm init to create a new module; this will prompt you a bunch of questions and will create a package.json file similar to this:
{
"name": "practice-karma",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Up to now, you should have the following folder structure:
practice-karma/
└── package.json
Now it's time to install Karma and the dependencies that we require to use Karma and Jasmine. In the practice-karma folder, run the following command:
$ npm install karma karma-jasmine jasmine-core karma-chrome-launcher --save-dev
The preceding command will install the dependencies required to use Karma and Jasmine, and also will add the dependencies to our package.json file into the devDependencies attribute. Open your package.json file, and you should see something similar to this:
{
"name": "practice-karma",
"version": "1.0.0",
...
"devDependencies": {
"jasmine-core": "^2.8.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.1"
}
}