The NATS CLI is a powerful tool to manage your NATS clusters. In this article, we will look at some tips and tricks that you can use to make your life easier.
If you haven’t used the NATS CLI yet, you can find more information how to install it here.
Using the —defaults flag
When creating streams, there’s a lot of knobs you can turn to configure your stream. When not providing all needed flags, the CLI starts in an interactive mode that runs a litte questionnaire.
If you want to create a lot of streams (e.g. for testing purposes), this can be a bit tedious.
The NATS CLI allows you to use the default values for these knobs by simply providing the
--defaults flag. Make sure that you have at least version 0.1.0 of the CLI to use this feature. Here’s an example for creating a stream.
When using the
defaults flag, all the defaults you would normally set by pressing enter get set automatically.
Using config files for quickly (re)creating resources
Let’s say you want to quickly recreate streams with the previous configuration. You could do this by saving the typed CLI command in a file but you could also save the configuration in a JSON file.
To save the config from an existing stream, you can use the following command, which saves the config in the
Now we want to reset the stream by deleting and recreating it. We can do that by using the
--config flag and pointing it to the
Using the context color scheme setting
When working with different NATS clusters, you can use the context color scheme setting to quickly identify the cluster you’re working with. If you set the color, every CLI output (e.g. listing streams) is styled with the selected color.
Make sure that you have at least version 0.1.0 of the CLI installed. Then you can use the following command to set the context color to the color of your choice:
Make sure the
EDITOR env is set to the editor of your choice. When your editor is open, navigate to the
color_scheme: "" line where you can configure one of the following colors:
yellow, blue, cyan, green, magenta or red.
Save the context file and run a command to make sure that your configuration works:
Using short command aliases
There are a lot of short form command aliases that saves you a few keystrokes. Here’s a list for common commands and their short form:
I hope that you found some tips and tricks that can help you to make your life easier when using the NATS CLI. If you prefer GUIs for managing NATS, please try Qaze. If you have any questions or feedback, feel free to reach out to me on X.