-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
learning: unstorage #79
Comments
Configuring storage drivers inside export default defineNuxtConfig({
nitro: {
storage: {
logs: {
driver: 'vercelKV',
base: 'incubrain:logs'
}
},
devStorage: {
logs: {
driver: 'fs',
base: './public/logs'
}
},
},
})
Then you can access the KV stores like so |
Built-in Driversunstorage has a range of built-in drivers, this list will likely grow. What I like is that we can easily swap out our drivers with a single line of code in the Anything marked as N/A is something I can't see us using in the future
|
Usage
Set in JavaScript (memory):It's a built-in object type for storing collections of unique values. It's great for quickly checking if a value is present in a collection, and for ensuring that there are no duplicates in the collection. However, Set only exists in memory and only lasts for the duration of the page session. If the page is refreshed or closed, the data in the Set is lost. This is ideal for storing unique values or objects within a single session, so examples might include:
localStorage:It's a type of web storage that allows JavaScript websites and apps to store key-value pairs in a web browser with no expiration time. This means the data stored in localStorage persists even after the browser or tab is closed, or after a page refresh. However, it has a maximum storage limit (usually 5MB) and it's not a good choice for storing sensitive data, as the data is not automatically encrypted and can be accessed by any code running on the same domain. This is best for storing data that should persist beyond the current session. Examples might include:
sessionStorage:It's similar to localStorage but has a shorter lifespan. Data stored in sessionStorage gets cleared when the page session ends (i.e., when the browser or tab is closed). Like localStorage, it also has a storage limit and is not ideal for storing sensitive data. This is useful for storing data that's only relevant to the current session, and should be cleared when the session ends. Examples could be:
|
Learnings:You need to define return types of What if we want an array? const storedArray = await storage.getItem<CustomType[]>(fileName) || []
storedArray.push(newValue)
const newArray = [...storedArray, ...moreValues] |
This will be a running thread of my findings about using unstorage with Nuxt/Nitro.
The text was updated successfully, but these errors were encountered: