Node JS Cookbook

Checkout Node JS In Hindsight

NOTE: the hindsight series are based on old HowTos and are being ported to the more recent versions. Some of this info may be presently out of date until this porting effort is finished.

1. Install node.js and npm (node package manager)
Official GitHub:

Setup with Ubuntu:

sudo apt-get update
curl -sL | sudo bash -
sudo apt-get install -y nodejs
sudo apt-get install npm
sudo apt-get install -y build-essential


brew update
brew install nodejs
brew install npm

2. Install phonegap

a. sudo npm install -g cordova
#note: for mac, there are additional tools installed on
b. sudo npm install -g ionic
c. sudo npm install -g bower
d. sudo npm install -g karma

NOTE: unlike bower, the npm install for karma does not create a sym link to the karma executable in /usr/local/bin on linux or /opt/local/bin on MacOSX. So you’ll need to do either

o) linux

sudo ln -s /usr/lib/node_modules/karma/bin/karma /usr/bin/karma

o) macosx

sudo ln -s /opt/local/lib/node_modules/karma/bin/karma /opt/local/bin/karm e. sudo npm install -g karma-jasmine

3. Install IDE(s)
NOTE: Android Studio Beta is a lightweight version of JetBrain’s Intellij IDEĀ  Android Studio does not support all the plugins that Intellij does but it can be used instead and it is free. Choose one or the other or both.

3A) Intellij Installation.
a. follow directions to install Intellij Ultimate.
b. run Intellij
c. File>Settings>IDE Settings>Plugins>Browse repositories
d. search for nodejs and install and restart
e. search for phonegap and install and restart
f. search for angularjs and install and restart

3B) Android Studio Beta Installation.
a. follow directions to install studio.
b. run android studio
c. File>Settings>IDE Settings>Plugins>Browse repositories
d. search for phonegap and install and restart

3C) Install XCode on mac

 cd $HOME/.cordova/lib/npm_cache/cordova-ios/{version#}/package/bin

4. Install Emulator packs
a. Run Tools > Android > Android SDK Manager
b. ensure 4.4.2 or greater packages are installed.
c. ensure ARM EABI v7a System image is also included

5. Install other bower components

a. bower install angular-mocks
b. bower install ngCordova
c. npm install angular-mocks
d. npm install angular-touch --save

6. Create simple phonegap project
6A) Using Cordova
a. cordova create hellogap com.zuut.hellogap HelloWorldFromGap
6B) Using ionic
a. ionic start <appname> <template>
templates:= blank, tabs, sidemenu
e.g. ionic start myApp sidemenu

7. To Add cordova plugins:

a. cordova plugin search device
b. cordova plugin add xxx

to view plugins

cordova plugin ls

to remove plugins

cordova plugin rm xxx

NOTE: typical plugins:
cordova plugin add org.apache.cordova.device
cordova plugin add org.apache.cordova.inappbrowser

8. Standard Cordova plugins
Basic device information (Device API):
cordova plugin add org.apache.cordova.device
Network Connection and Battery Events:
cordova plugin add
cordova plugin add org.apache.cordova.battery-status
Accelerometer, Compass, and Geolocation:
cordova plugin add org.apache.cordova.device-motion
cordova plugin add org.apache.cordova.device-orientation
cordova plugin add org.apache.cordova.geolocation
Camera, Media playback and Capture:
cordova plugin add
cordova plugin add
cordova plugin add
Access files on device or network (File API):
cordova plugin add org.apache.cordova.file
cordova plugin add org.apache.cordova.file-transfer
Notification via dialog box or vibration:
cordova plugin add org.apache.cordova.dialogs
cordova plugin add org.apache.cordova.vibration
cordova plugin add org.apache.cordova.contacts
cordova plugin add org.apache.cordova.globalization
cordova plugin add org.apache.cordova.splashscreen
Open new browser windows (InAppBrowser):
cordova plugin add org.apache.cordova.inappbrowser
Debug console:
cordova plugin add org.apache.cordova.console

9. Building. Note: if checking out a project, you must add
the project’s required plugins first otherwise you’ll get an error
6A) Using Cordova
a. Add plugins using

cordova plugin add ...
b. cordova platform add android
c. cordova platform add browser --usegit
d. cordova build

e. You can use cordova to run an emulator or ripple to run a local
web server for testing html (no plugins).
i) cordova run –emulator [–target=XXX]

cordova run --emulator --target="iPad (Retina)"
see {project-root}/platforms/ios/cordova/run for ios options

6B) Using ionic
a. Add plugins using

ionic plugin add ...
b. ionic platform add android
c. ionic platform add browser --usegit
d. ionic build
e. ionic serve or
ionic emulate android

10. In Intellij/Android Studio, import the new project.
a. In the import project wizard, add directories and click next.
Source files are:
b. Add libraries (use default) and click next
c. Add Modules (use default) and click next
d. Add project SDK (use 4.4.2) and click next
e. Add frameworks (use default) and click Finish.
f. Now File > Project Structure > Modules >Module ‘android’ >Add Content Root
and add the www folder immediately under the project root
11. Updating platform
After installing the cordova utility, you can always update it
to the latest version by running the following command:
$ sudo npm update -g cordova

Use this syntax to install a specific version:

$ sudo npm install -g cordova@3.1.0-0.2.0
Run cordova -v to see which version is currently running.
Run the npm info command for a longer listing that includes
the current version along with other available version numbers:
$ npm info cordova

Cordova 3.0 is the first version to support the command-line interface
described in this section. If you are updating from a version prior to
3.0, you need to create a new project as described above, then copy
the older application’s assets into the top-level www directory. Where
applicable, further details about upgrading to 3.0 are available in the
Platform Guides. Once you upgrade to the cordova command-line interface
and use npm update to stay current, the more time-consuming procedures
described there are no longer relevant.

Cordova 3.0+ may still require various changes to project-level directory
structures and other dependencies. After you run the npm command above
to update Cordova itself, you may need to ensure your project’s resources
conform to the latest version’s requirements. Run a command such as the
following for each platform you’re building:

$ cordova platform update android
$ cordova platform update ios