Cordova Installation

We will examine the CLI approach to Cordova development. The Command Line Interface, or CLI, is the user interface with a computer operating system. It underlies and supports the more famiiliar Graphical User Interface, or GUI, used by most computer systems. It is a text based system where specific commands have to be entered by typing commands at a text prompt instead of the event driven selection process adopted by window based systems. So it is not as easy to use as the GUI.

For a Windows computer, you can access the CLI by clicking on the Start icon in the bottom left corner of the screen. Then you can scroll down the options displayed to select the Windows System then the Command Prompt, which is the Windows 10 version of the CLI. There are faster ways that you can learn and alternatives for non-Windows systems, but you will generally end up with a black screen and text displayed. This shows you what directory you are currently in. On my computer is displays the prompt,

C:\Users\Bill>

followed by a flashing cursor waiting to receive my next command.

It shows that I am in the hard disc C, directory, Users, and subdirectory, Bill. In a window-based interface we would probably refer to these directories as folders.

I start the process by enteriing cd\ which chooses the root directory on my computer, C and ends up showing

C:\>

Again followed by the flashing text cursor. And we are ready to start programminng the CLI.

 

Environmental Paths

When an application runs it often has to use other applications and data to complete various actions. So it needs to find these applications in the computer. To enable this process, the paths to all these applications and variable locations are stored either in the primary application itself or, in the present case, in the Environmental Variable list. Then the main application looks up the path, adds it to the application name and runs the application.

For Windows, you can access these paths from the Start menu by selecting Windows System and then the Control Panel. This opens the Control Panel window which is a regular GUI. You have to select System and Security then System then you are faced with a geneal information screen with an option on the left to let you select Advanced system settings. Clicking this takes you, at last, to the Environmental Variables window. This has a panel with System variables that you may have to edit.

For other operating systems you should do a Google search to find the corresponding operations to editt the Environmental Variables..

At this point you should be very careful since incorrect settings of these variables may cause your computer to behave badly.

If you have to edit a path variable you will find it listed in the lower pane. This is a list of paths separated by semicolons. It is probably too long to fit in the panel but clicking the value to select it then clicking the Edit button should list all the values in the path variable in a new window.by

As an example, the first path we will look at is for a package called Node. This normally sets its own path so when you have installed it there should be an entry something like

C:\Program Files\nodejs\

This is the path to the Node software whose complete address is

C:\Program Files\nodejs\node

It is also the path to C:\Program Files\nodejs\npm which we will also use in the next section.

If the path you require is missing you should add it by clicking the New button and entering the path. If it is present but incorrect, you can edit it.  Of course, all of this activity calls for very careful typing.

If you have edited a path and want to keep the new value you should exit all the windows in reverse order by clicking their OK buttons. If you just exit the windows your path edits will not be saved.

If you have a correct path set to Node then opening the Command Prompt window and entering the command  node –v  should find node and display its version number. Otherwise you will get some sort of error message, in which case you have to go back and set the path again.

Installing Cordova

To install Cordova you have to first install Node. Cordova is a JavaScript app that is run by the Node runtime engine, node.js, so you start installing Cordova by installing node.js.  Then you use the Node package manager from the system command line to install Cordova. This installs the Cordova CLI which contains all the commands you need for hybrid development from the system command line.

Node             

This package can be installed directly from its website at https://nodejs.org/en/download. As usual with such downloads, you can download then run the app from the browser. Or when download is complete you can exit the browser and install the application by finding it in your Downloads folder and double clicking it. Node should set its own path in environmental variables and you can check that this has been done correctly with the system command

 node –v 

This should find node and display its version number. Otherwise you will get some sort of error message, and you should check that Node has been installed and set the path properly.

 

Cordova

Cordova is installed from the Command Prompt by the Node package manager, npm.. You have to enter the command

 npm install –g cordova

As usual, it will install Cordova even if your use a lower case initial since that is the name of the application it will find. And the g switch simply makes it a global install with its path set.

You can check the success of your installation with

cordova –version

This should display the version number of Cordova.

Again, Cordova should set its own path variable but if the version number is not returned you should find where it has been installed, probably in your Program Files folder then make another trip to the environmental variables window and check that its path is correct.

If the command does display a version number, Cordova is installed along with a complete set of its own CLI commands. Now you can develop, test and run Cordova apps entirely from the Cordova CLI.

At this point it is worth noting that the Windows command prompt follows the usual Windows practice in terms of file and folder names. When you create a new name the character case is stored. So Web is different from web and will always be referred to by the prompt as Web. However, the system will accept input as Web or web and can’t really distinguish between them.

So C:\Web can be entered as c:\web and will find and display C:Web.

You can exit the command prompt window by clicking the usual window x button or entering the command, exit.