|
| 1 | +--- |
| 2 | +title: CLI Basics |
| 3 | +contributors: |
| 4 | + - Ombuweb |
| 5 | + - rigor789 |
| 6 | +--- |
| 7 | + |
| 8 | +When working with NativeScript, you will often interact with the NativeScript CLI. The CLI is self-documented, so you can always run `ns --help` or `ns <command> --help` to view available commands, flags and descriptions. |
| 9 | + |
| 10 | +This page is a quick reference for useful development commands, but it's not meant to be an exhaustive list of all the commands. |
| 11 | + |
| 12 | +**The following workflows have their dedicated pages with further information:** |
| 13 | + |
| 14 | +- [Running](/guide/running) |
| 15 | +- [Debugging](/guide/debugging) |
| 16 | +- [Publishing](/guide/publishing/) |
| 17 | + |
| 18 | +## Cleaning |
| 19 | + |
| 20 | +### Cleaning a single project |
| 21 | + |
| 22 | +When you're installing plugins with native dependencies or updating runtime versions, it's a good practice to perform a clean build. |
| 23 | +This helps ensure everything fits together correctly. If you're dealing with mysterious build errors, they might disappear after a clean build. |
| 24 | + |
| 25 | +To clean, run this command from your project's root directory: |
| 26 | + |
| 27 | +```cli |
| 28 | +ns clean |
| 29 | +``` |
| 30 | + |
| 31 | +Running `ns clean` removes the `node_modules`, `hooks`, and `platforms` directories. You can customize what's cleaned in the [nativescript.config.ts](/project-structure/nativescript-config#cli-pathstoclean). |
| 32 | + |
| 33 | +### Cleaning multiple projects |
| 34 | + |
| 35 | +If you have multiple projects piled up in your projects folder, and would like to free up some disk space, you can run `ns clean` in your projects folder, and it will scan for any valid NativeScript projects in sub-directories and the prompt you to choose the ones to clean. |
| 36 | + |
| 37 | +<DeviceFrame type="ios"> |
| 38 | +<video controls src="https://user-images.githubusercontent.com/879060/230395606-dbb4a56f-74e8-403b-a687-62e27a61f8d4.mov"></video> |
| 39 | +</DeviceFrame> |
| 40 | + |
| 41 | +## Listing connected devices |
| 42 | + |
| 43 | +To list all connected devices (both physical and virtual), run: |
| 44 | + |
| 45 | +```cli |
| 46 | +ns devices |
| 47 | +``` |
| 48 | + |
| 49 | +Example output: |
| 50 | + |
| 51 | +``` |
| 52 | +| # | Device Name | Platform | Device Identifier | Type | Status | Connection Type | |
| 53 | +| - | -------------- | -------- | ------------------------------------ | -------- | --------- | --------------- | |
| 54 | +| 1 | Pixel 4 API 33 | Android | emulator-5554 | Emulator | Connected | Local | |
| 55 | +| 2 | generic_device | Android | XXXXXXXXXXXXXX | Device | Connected | USB | |
| 56 | +| 3 | iPhone 14 Pro | iOS | XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | Emulator | Connected | Local | |
| 57 | +``` |
| 58 | + |
| 59 | +## Setting the default package manager |
| 60 | + |
| 61 | +To set the default package manager that the CLI uses (unless overridden in [nativescript.config.ts](/project-structure/nativescript-config#cli-packagemanager)): |
| 62 | + |
| 63 | +```cli |
| 64 | +ns package-manager set npm |
| 65 | +ns package-manager set yarn |
| 66 | +ns package-manager set yarn2 # experimental |
| 67 | +ns package-manager set pnpm |
| 68 | +``` |
0 commit comments