Loading, please wait...

How to setup and create Cordova App using CLI

Jan 13, 2020 Cordova, Cordova CLI, 109 Views
In this article, you’ll see how to setup Cordova for mobile application development with NPM packages and JS frameworks like angular.

The very first thing that we need is NPM to be installed in the system. So, let’s do that first and follow the steps:

Step 1:

This is an optional step you can skip this if you have Node JS already installed on your system, if not so open https://nodejs.org and find the option to download as per your system configuration:

Once you download and installed it successfully, try to run the “npm” command on the command prompt or terminal, if it’s given you options to choose that means it’s installed and configured well.

Step 2:

Now Type the following command to install Cordova CLI

npm install -g cordova

Step 3:

Before moving ahead, I would suggest you install an Android studio and set up an emulator to test your app in the local system only.

Download Android Studio

After Install open Android Studio, click on the configure button.
Now find an option ADB Manager and create a new virtual device.
Trust me this is the only way by which you can use free open-source Emulators. Once you are done with it, so start an Emulator before creating and running a Cordova mobile app because it’ll take much time the first time to be ready.

You can use a real device to test the debug APK.

Step 4:

Now time to create a new Cordova project using CLI. So, Type the following commands and follow the same:

Command 1:

cordova create hello com.example.hello HelloWorld

This command will create a new “Hello World” app with “com.example.hello“ package name.

Now come to the project folder with the “cd hello” command.

Command 2:

cordova platforms ls

Using this command, we can check the Installed platform in the project and Available platforms in the system.

But as this is the new project so we don’t have any Installed platforms in the project.

Command 3:

cordova platform add ios
cordova platform add android

Using this command we can add any required platform as per need, Android or iOS.
Now if you want to check the installed platforms, so use the second last command.

cordova platforms ls

You’ll see this time that Android is Installed in the project.

Command 4:

cordova run

This is the last command for this first hello world project, this command will build and run the Cordova project in the Emulator that to stared in step 2.

First, it’ll build the changes and it will make a local debug copy of the “APK” file and will launch in the emulator.
I hope you’ll get the same output in your emulator or device.