Registry / storage / nuxt-storage

nuxt-storage

JSON →
library1.2.2jsnpmunverified

Utilities for easy read and write browser's storage in Nuxt.js projects, wrapping localStorage and sessionStorage with a simple API. Version 1.2.2 (latest, not actively updated since 2019). Provides get, set (with expiry), and clear methods. Specifically solves the Nuxt SSR hydration issue where direct access to browser storage causes errors. A lighter alternative to larger libraries like vue-store or vue-web-storage.

npm install nuxt-storage
INSTALL
IMPORT
SIG · NUXT-STORAGE
N
nuxt-storage
storagejavascriptv1.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import nuxtStorage from 'nuxt-storage'
const nuxtStorage = require('nuxt-storage').default
ESM default import in client-side Nuxt. Do not destructure unless importing explicitly from subpaths.
setData
import { setData } from 'nuxt-storage/local-storage'
import { setData } from 'nuxt-storage'
Named export only available from subpath, not the main entry.
getData
import { getData } from 'nuxt-storage/session-storage'
import { getData } from 'nuxt-storage'
Session-storage variant must be imported from its own subpath.

Set, get, and clear localStorage with optional expiry (hours) using the default import.

// Install: npm i nuxt-storage import nuxtStorage from 'nuxt-storage' // Store data with 5-hour expiry nuxtStorage.localStorage.setData('token', 'abc123', 5, 'h') // Retrieve data const token = nuxtStorage.localStorage.getData('token') console.log(token) // 'abc123' // Check if data exists if (token) { console.log('Token found') } else { console.log('Token expired or missing') } // Clear all localStorage nuxtStorage.localStorage.clear()
Debug
Known issues
gotchaDo not use outside of client-side hooks (e.g. before mounted) – server-side render will fail
fix
Wrap usage with `if (process.client)` or use inside `mounted()`
affects: >=1.0.0
deprecatedPackage is no longer actively maintained; last update 2019
fix
Consider using localforage or integrating directly with browser Storage API
affects: >=1.0.0
gotchaExpiry is stored only in localStorage as a JSON value; modifying storage externally may break expiry
fix
Do not manipulate localStorage keys manually if using nuxt-storage expiry
affects: >=1.0.0
gotchaImport from subpaths like 'nuxt-storage/local-storage' must be the exact string; no auto-complete
fix
Use the exact import path as documented; check node_modules folder if unsure
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getItem')
Server-side rendering tries to access window/localStorage which is undefined in Node
fix
Use `if (process.client)` before accessing, or call inside `mounted()` lifecycle hook
Cannot find module 'nuxt-storage/local-storage' or its corresponding type declarations
TypeScript definitions are not included; package has no types
fix
Create a manual declaration file: `declare module 'nuxt-storage/local-storage';`
Uncaught SyntaxError: Unexpected token N in JSON at position 0
Storing non-serializable data or data without JSON.stringify
fix
Only store data serializable to JSON; use `JSON.stringify` before storing
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
nuxt-storage — npm install nuxt-storage · libregistry