Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including nativescript-platform with all npm packages installed. Try it out:

var nativescriptPlatform = require("nativescript-platform")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nativescript-platform v1.3.1

A NativeScript plugin to easily deal with getting the platform running on

npm npm npm Twitter Follow


A NativeScript plugin to easily deal with and detect which platform you are on

Developed by



This is released under the MIT License, meaning you are free to include this in any type of program -- However for entities that need a support contract, changes, enhancements and/or a commercial license please contact me at

I also do contract work; so if you have a module you want built for NativeScript (or any other software projects) feel free to contact me

Donate Patreon


Any version of NativeScript


tns plugin add nativescript-platform


To use the module you just require() it:

var myPlatform = require( "nativescript-platform" );
if ( {
  // do android specific stuff

please note you can also simple do, and then the nsPlatform will be available globally everywhere:

require( "nativescript-platform" );
if (nsPlatform.ios) {
 // do ios specific stuff

nsPlatform will be declared globally. My recommendation is just to include it in the app.js and then use it everywhere.

You ask, how exactly does this help?

This wraps up several simple ways to check for the platform you are on. This comes up commonly when you are trying to do stuff on just one platform.

Breaking changes

Removed initial windows phone support, its been 4 years -- I don't think NativeScript will ever build actual windows phone apps.



  • .isAndroid();
  • .isIOS(); returns true or false depending on the platform it is on Example:
if (nsPlatform.isAndroid()) { /* do my android specific stuff */ }
  • .hasSoftNav(); returns if device is using Soft Navigation.


  • .ios
  • .android
  • Is set to either true or false for the platform it is on Example:
if (nsPlatform.ios) { /* do my ios specific stuff */ }

Switch Statement support


  • .type.IOS
  • .type.ANDROID Example:
switch (nsPlatform.platform) {
  case nsPlatform.type.IOS:     // Do iOS stuff
  case nsPlatform.type.ANDROID: // Do Android stuff


Tablet or Phone


  • .width - Width of Screen (DIP)
  • .height - Height of Screen (DIP)
  • .scale - Scale of Screen (DIP)
  • .widthPixels - Width of Screen (Pixels)
  • .heightPixels - Height of Screen (Pixels)


  • .emulator - True or False
  • .model - Model number of device
  • .name - Name of device (might be the same as model)
  • .manufacturer - Manufacturer of the device
  • .notch - true or false, if device has a notch.
  • .buttonLess - true or false, APPLE only -- if the device has no home button. ( .hasSoftNav() supports both android and ios )
// Outputs: "Apple iPhoneX"
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free