Package.json file in Protractor

Package.json provides a simple way for people to keep track of packages they use in their application.

This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies. It can also contain other metadata such as a project description, the version of the project in a particular distribution, license information, even configuration data - all of which can be vital to both npm and to the end users of the package. The package.json file is normally located at the root directory of a Node.js project.
 


Prerequisite to create package.json: node js should be installed and setup should be done.

1. Create Project folder as "Framework" in drive.

2. Open a command prompt cmd and navigate to project folder like below

C:\WINDOWS\system32> CD "pathOfProjectFolder"

Example : CD C:\Users\Framework

3. Execute the "npm init" command. It will ask you a bunch of questions, and then write a package.json for you in project directory.

Example : C:\Users\Framework> npm init

4.  Dependencies in package.json: There are 2 types of packages.

dependencies: These packages are required by your application in production.
devDependencies: These packages are only needed for development and testing.


5. Adding new package:

Add new package in key/value pair in package.json

Example:

"devDependencies" : {
    "package_name": "^version_number"
  }


6. Installing Package:
npm install <package_name>

This will create the node_modules directory in your current directory (if one doesn't exist yet) and will download the package to that directory.

7.  If you have a package.json file in your directory and you run npm install, npm will look at the dependencies that are listed in that file and download under "node_modules" folder.

8. Once the package is in node_modules, you can use it in your code. For example, if you are creating a Node.js module, you can use require in Javascript and import in Typescript .

For more details, info have a look on & Reference: https://dev.to/xabadu/you-me-and-package-json-1dc2


Comments

Popular posts from this blog

Debugging in Protractor

Config file in Protractor

Handling Keyboard actions in Selenium