Book Image

Getting Started with NativeScript

By : Nathanael J. Anderson
Book Image

Getting Started with NativeScript

By: Nathanael J. Anderson

Overview of this book

NativeScript allows you to build a fast cross-platform application that has a native UI. NativeScript is a true cross-platform framework that generates native speed applications using the native components of the host platform, all using JavaScript. Although NativeScript allows you to build your application in JavaScript, you have full access to the host OS from your code, allowing you to easily tweak or use new platform features instantly at native code speeds. Whether you have already developed multiple applications or zero applications, this book will help you to develop your next application in a cross-platform framework quickly, saving you a massive amount of time and money. This book concisely shows you NativeScript’s built-in framework that allows you to rapidly develop a fully-working compiled cross-platform application in just a few chapters. It starts by laying the foundation of NativeScript and working through the fundamentals to create a basic shell of the application. Moving on, you’ll see how to build a full-fledged application step by step. We’ll show you how to use plugins, and how to communicate with the native OS libraries easily so that you can customize your application as if your app was created in Java or Objective C. We then deal with the issues that arise from being cross platform and compensate for the different screen sizes, screen resolutions, and device abilities. Finally, we progress to testing and deploying your app.
Table of Contents (15 chapters)
Getting Started with NativeScript
About the Author
About the Reviewer


Welcome to Getting Started with NativeScript. In this book, we are going to go on an awesome journey of building cross-platform applications in JavaScript. We will cover everything from how NativeScript works, to how to test, debug, and finally deploy your application. Over the course of this book, we are going to explore how to build a full-featured, cross-platform messaging platform. The application will work the same on all NativeScript-supported platforms. With your ability to develop in JavaScript and the insights provided in this book, you will be releasing your own cool applications in no time.

What this book covers

Chapter 1, Introduction to NativeScript, will teach you about NativeScript and how to install and build your first NativeScript application.

Chapter 2, The Project Structure, provides an overview of what all the different files and folders are used for, and we will build and switch to a second screen for our application here.

Chapter 3, Declarative UI, Styling, and Events, works through how to create screens using the Declarative UI, style them and then how to create and respond to events.

Chapter 4, Building a Featured Application, helps you to actually sit down and build a full-featured, cross-device messaging application using just the standard NativeScript components.

Chapter 5, Installing Third-Party Components, delves into how to install several different types of third-party components to enhance our cool communication application.

Chapter 6, Platform Differences, looks at how to deal with the differences between iOS and Android and the differences in the actual physical characteristics of the devices even on the same platform.

Chapter 7, Testing and Deploying Your App, looks at how to use several different types of testing frameworks, how to debug your application, and finally, how to actually deploy your application.

What you need for this book

NativeScript is an open source project; as such, it uses technologies that can be freely downloaded from the Internet. You need to download and install a recent version of Node from You also need a text editor so that you can edit your source code. If you are developing for Android, you need to download and install Java 7, Gradle 2.3, and the Android SDK. For iOS, you need to install Xcode 6.2 or a later version.

Who this book is for

If you are already a JavaScript developer and you want to finally build native cross-platform applications for iOS and Android using your skills, then this book is just for you!


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "which a require statement would load into your code."

A block of code is set as follows:

  "name": "tns-template-hello-world",
  "main": "app.js",
  "version": "1.5.0",
  ... more json documentation fields...

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

  "nativescript": {
    "id": "org.nativescript.crossCommunicator",
    "tns-android": {
      "version": "1.5.0"

Any command-line input is written as follows:

nativescript run ios --emulator

New terms and important words are shown in bold or italics. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "You can probably guess that the Label will still say Tap the button."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.