Storing and Posting Data

Learn how to interact with in-memory storage.

The Nitro server has a built-in storage layer for storing our data. It can be stored in a filesystem, database, or any other external store. Some of the available built-in drivers include Redis, local storage, and memory.

In memory storage

For simplicity and to focus on the server alone, we will use the default in-memory storage. This means our data will be stored locally in memory and will not be persistent. It is not a permanent storage solution, and data will be lost when the application reloads. For a permanent solution in production, we would need to set up an external database. However, this method will allow us to test out the storage methods available during development.

The useStorage utility

To interact with our data store, Nuxt provides various methods. The useStorage utility is available to use in our server automatically due to auto-import. It provides methods we can use to get and set data, to set data to the store we have setItem.

Setting data

This setItem method will take in a key and a value. The key will be used to reference the stored data when we want to retrieve it, and the value is the data to store:

Get hands-on with 1200+ tech skills courses.