package.json API
Alongside config.xml, every Cordova project created with the CLI also has a standard npm package.json file. Cordova reads and writes fields inside package.json to keep track of your project's platforms and plugins.
This page lists the Cordova-specific fields you may find in your package.json, and explains when and how the CLI updates each one, so that you know what's safe to edit by hand and what's managed for you.
Sample package.json:
{
"name": "io.cordova.hellocordova",
"displayName": "HelloCordova",
"version": "1.0.0",
"description": "Sample Apache Cordova App",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"cordova": {
"platforms": [
"android",
"ios"
],
"plugins": {
"cordova-plugin-device": {}
}
},
"devDependencies": {
"cordova-android": "^13.0.0",
"cordova-ios": "^7.0.0",
"cordova-plugin-device": "^2.1.0"
}
}
name, displayName, version
Set automatically when a project is first created with cordova create, alongside config.xml. Cordova does not go back and update these values later if config.xml changes.
| Field | Description |
|---|---|
| name | Copied from config.xml's widget id attribute (the app's reverse-DNS identifier), converted to lowercase. |
| displayName | Copied from config.xml's <name> element (the app's human-readable name). |
| version | Copied from config.xml's widget version attribute. |
Examples:
{
"name": "io.cordova.hellocordova",
"displayName": "HelloCordova",
"version": "1.0.0"
}
cordova.platforms
An array listing the platforms currently installed in the project. Entries are added automatically when you run cordova platform add <platform>, and removed when you run cordova platform remove <platform>. Adding a platform that's already listed will not create a duplicate entry.
Automatic saving can be turned off with the --nosave flag.
Examples:
{
"cordova": {
"platforms": ["android", "ios"]
}
}
cordova platform add android
cordova platform add ios --nosave
cordova.plugins
An object listing the plugins currently installed in the project. Each key is a plugin's ID, and its value holds any CLI variables that were supplied when the plugin was installed (or an empty object if none were needed). Entries are added by cordova plugin add <plugin> and removed by cordova plugin remove <plugin>. Automatic saving can be turned off with the --nosave flag.
Examples:
{
"cordova": {
"plugins": {
"cordova-plugin-camera": {},
"cordova-plugin-some-plugin": {
"API_KEY": "my-api-key"
}
}
}
}
cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-some-plugin --variable API_KEY=my-api-key
devDependencies
A standard npm field, not unique to Cordova. See npm's docs on devDependencies for the general behavior. When a platform or plugin is installed, Cordova's tooling also records it here as an npm dependency, alongside its installed version number. This is separate from cordova.platforms and cordova.plugins, devDependencies tracks the actual npm package and version that was fetched.
Automatic saving can be turned off with the --nosave flag.
Examples:
{
"devDependencies": {
"cordova-android": "^13.0.0",
"cordova-plugin-camera": "^7.0.0"
}
}
CLI --nosave Flag
By default, cordova platform add and cordova plugin add automatically save what you installed into package.json. If you'd rather install something without permanently adding it to your project's configuration, for example, to test a plugin temporarily, pass the --nosave flag:
cordova platform add android --nosave
cordova plugin add cordova-plugin-camera --nosave
This applies to cordova.platforms, cordova.plugins, and devDependencies all at once, there's a single flag, not one per field.