|
| 1 | +export const description = 'Local development with Nitric' |
| 2 | + |
| 3 | +# Local Development |
| 4 | + |
| 5 | +One of the key features of the Nitric CLI is the ability to run your application locally, using an environment that closely resembles what would be run in the cloud. This allows you to test your application locally before deploying it to the cloud. |
| 6 | + |
| 7 | +Nitric is able to run a local environment that can serve your application, as well as any other services that your application may depend on such as queues, buckets, secrets, etc. This is done by using the `nitric start` command to run your application directly or by using `nitric run` to use Docker to run your application in containers, in both cases any other services that your application may depend on are either hosted by the CLI directly or by using Docker containers. |
| 8 | + |
| 9 | +## Running your application directly |
| 10 | + |
| 11 | +To run your application, you can use the `nitric start` command. This command starts your application and any other services it depends on. This is the recommended way to run your application locally as it is the simplest way to run your application, starts the fastest and makes attaching other tools like debuggers easier. |
| 12 | + |
| 13 | +```bash |
| 14 | +nitric start |
| 15 | +``` |
| 16 | + |
| 17 | +Once the command starts, you'll be presented with a list of your running APIs and other services. You'll also see a link to the [local development dashboard](/getting-started/local-dashboard) where you can view a live architecture diagram of your running application and interact with various services for testing. |
| 18 | + |
| 19 | +<img |
| 20 | + src="/docs/images/docs/dashboard-architecture.png" |
| 21 | + style={{ maxWidth: 800, width: '100%' }} |
| 22 | + alt="screen shot of the local development dashboard" |
| 23 | +/> |
| 24 | + |
| 25 | +## Running your application in Containers |
| 26 | + |
| 27 | +If you prefer to run your application in containers, you can use the `nitric run` command. This command builds and runs your application in Docker containers (one per service), along with any other services it depends on. This is useful if you want to run your application in an environment that more closely resembles the cloud, or if you want to run your application in a containerized environment. That said, this method is slower to start and may require more resources than running your application directly, it also makes attaching other tools like debuggers more difficult. |
| 28 | + |
| 29 | +```bash |
| 30 | +nitric run |
| 31 | +``` |
| 32 | + |
| 33 | +The output for this command will be similar to the `nitric start` command. |
| 34 | + |
| 35 | +## Stopping your application |
| 36 | + |
| 37 | +In either case you can stop your application by pressing `Esc` or `Ctrl+C` in the terminal where you started your application. |
| 38 | + |
| 39 | +## Enabling Https for local development |
| 40 | + |
| 41 | +By default, Nitric will run your application's APIs and HTTP Proxies over HTTP to avoid common issues with self-signed certificates. In most cases, this is sufficient for local development. However, if you need to test your application over HTTPS, the `nitric start` command supports enabling HTTPS using the `--https-preview` flag. |
| 42 | + |
| 43 | +This command will generate a self-signed certificate and key for your application and use them to serve your application over HTTPS. This is useful if you need to test your application over HTTPS locally, but keep in mind that self-signed certificates are not trusted by browsers and may cause security warnings. |
| 44 | + |
| 45 | +```bash |
| 46 | +nitric start --https-preview |
| 47 | +``` |
| 48 | + |
| 49 | +If you need use a custom certificate and key, you can place them in the `.nitric/tls` directory in your project and Nitric will use them to serve your application over HTTPS. The files must be named `cert.pem` and `key.pem` respectively. |
| 50 | + |
| 51 | +<Note>This feature is experimental and may change in future releases.</Note> |
0 commit comments