Home » cypress-tutorial » Creating package.json file

Newly Updated Posts

Creating package.json file

Previous Topic , In this tutorial, we are going to learn Creating package.json file inside Visual Studio Code and creating Cypress Project.

What is package.json file? and Whats its use for?

As it name referrers, it a json file which resides in the root of the project and stores metadata
of the current project, its key role is managing all the dependencies and successfully
running the script in our local machine. We will be taking the example for 2 dependencies in our package.json file to understand more in details with the help of NPM commands. But going further we need to understand NPM is depth.

What is NPM? Creating package.json file

NPM refers to Note Package manager, All the developer who develops JavaScript based packages hosts all their package in to this node package manager to its npm Website -> https://www.npmjs.com/.

As we run npm command what it initially does is, it reads all the dependencies from package.json file and after reading json file it directly connects to its repository https://www.npmjs.com/. and search for the dependencies with its version number and pulls it from npm repository to our local project. Similarly it continues this process for all the dependencies defined in project.json file. Due to this reason Package.json is said to be the heart of the node project. So where ever we are working JavaScript or node project , we need to create package.json file.

Steps to Create Package.json file through VC Terminal

1) Go to the terminal create a folder with preferred name ex( CypressProject) and move to the folder. Below are the commands:

//this command will create folder with name CypressProject
mkdir CypressProject

//this command with move to CypressProject Folder
cd CypressProject
Creating package.json file - Create Directory

2) Now create npm project with below command

// Command 
npm -i init
Creating package.json file - default

3) Now the terminal would ask you multiple pre-requisite (ex: package name, version etc) . Click to Enter for every pre-requisite or keep it on default data, till the json file gets generate on terminal (refer the screenshot)

Creating package.json file - Terminal

4) At last type “Yes” for question Is this OK?

Creating package.json file -  Is this OK?

5) Now setup cypress dependency on using the below npm command and hit enter.

//This command will install cypress dependency
npm install cypress --save-dev
npm install Cypress --save-dev

6) As we hit command npm start download , unzip and finish Cypress dependency.

Download unzipping Cypress

7) Once the Installation is completed click to open folder and select the folder we created above (CypressProject) from directory

Folder in Visual Studio

8) Now we are completed with creation of VC project. Click to package.json file where you can see all the dependency mentioned on .json file as per below screenshot

package.json