
PhoneGap By Example
By :

When working with older versions of PhoneGap, we have to make a lot of detailed settings of the environment in order to run the application. However, with the newer versions, starting from 5.0.0, this procedure becomes easier. Before installing PhoneGap, we need to install Node.js, because it is easier to install PhoneGap CLI as a ready-to-use NPM package without compiling it from source codes. And NPM is a utility of Node.js.
Node.js is a platform built on Chrome's JavaScript runtime. It was built as a tool for fast and scalable network applications. The main feature of the framework is an event-driven, non-blocking I/O model. For now, it is mainly used on server side in the same way as PHP, Ruby, or others. However, it is very popular and spreading fast nowadays.
There are several ways to install Node.js, but I will describe only two of them.
We will see how to install Node.js from the official website and with Homebrew.
To install Node.js, you can download a pre-compiled binary package, which makes for a nice and easy installation. Follow these steps:
/usr/local/bin
is in your path. Double-check that you have it by running in the terminal using this command:$ echo $PATH
If not, add it in either .bash_profile
or .bashrc
in your home directory.
$ node > console.log('PhoneGap by Example'); PhoneGap by Example undefined
Another good way to install Node.js is using Homebrew.
Homebrew (http://github.com/mxcl/homebrew) is the package manager that Apple forgot. Written in Ruby, it allows you to quickly and easily compile software on your Mac.
To install Homebrew (http://brew.sh/), follow these steps:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The script explains what it will do and then pauses before it does it. It might require you to execute sudo
and enter your root password. You should wait for a while to download and install all the components.
==> Installation successful! ==> Next steps Run `brew doctor` before you install anything Run `brew help` to get started
brew install node
It might require root access from you as well. And that is it. Node.js is installed now. It is pretty easy, right?
node –v
. This should print a version number.npm -v
in the terminal. This should print NPM's version number.To install Node.js on Linux, we should be familiar with the terminal as well. First of all, we need to install dependencies. Follow these steps:
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
sudo yum groupinstall 'Development Tools' && sudo yum install curl git m4 ruby texinfo bzip2-devel curl-devel expat-devel ncurses-devel zlib-devel
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
After that, we need to add the following three lines to .bashrc
or .zshrc
:
export PATH="$HOME/.linuxbrew/bin:$PATH" export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH" export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
So, all the prerequisites are done, and we can install Node.js now. There are only two steps left to follow:
brew install node
.Now, we can test Node.js and NPM by running node -v
and npm -v
in the terminal accordingly.
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Change the font size
Change margin width
Change background colour