{"library":"redux-persist-node-storage","title":"Redux Persist Node Storage Adapter","description":"Redux-persist-node-storage is an adapter for the Redux Persist library, enabling state persistence in Node.js environments. It achieves this by implementing Redux Persist's required storage interface (`setItem`, `getItem`, `removeItem`, `getAllKeys`) using `node-localstorage`. The package provides a `localStorage`-like API for Node.js, making `redux-persist` usable in server-side applications, Electron apps, or other Node.js contexts where browser `localStorage` is unavailable. Data is stored on disk in a user-specified directory. The current stable version is 2.0.0, released in December 2017. Due to its age and lack of recent updates, its release cadence is effectively non-existent, and it primarily serves a niche requirement for Node.js-specific Redux state persistence.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install redux-persist-node-storage"],"cli":null},"imports":["import { AsyncNodeStorage } from 'redux-persist-node-storage';","import { NodeStorage } from 'redux-persist-node-storage';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createStore, combineReducers } from 'redux';\nimport { persistStore, persistReducer } from 'redux-persist';\nimport { AsyncNodeStorage } from 'redux-persist-node-storage';\nimport path from 'path';\n\n// A simple reducer\nconst userReducer = (state = { name: 'Guest', loggedIn: false }, action) => {\n  switch (action.type) {\n    case 'LOGIN':\n      return { ...state, name: action.payload.name, loggedIn: true };\n    case 'LOGOUT':\n      return { ...state, name: 'Guest', loggedIn: false };\n    default:\n      return state;\n  }\n};\n\nconst rootReducer = combineReducers({\n  user: userReducer,\n});\n\n// Configure redux-persist for Node.js\nconst storageDir = path.join(process.cwd(), './tmp/persist-storage');\nconst storage = new AsyncNodeStorage(storageDir);\n\nconst persistConfig = {\n  key: 'root',\n  storage,\n};\n\nconst persistedReducer = persistReducer(persistConfig, rootReducer);\n\nconst store = createStore(persistedReducer);\nconst persistor = persistStore(store, null, () => {\n  console.log('Redux store rehydrated!');\n  // Example: Dispatch an action after rehydration\n  // store.dispatch({ type: 'LOGIN', payload: { name: 'NodeUser' } });\n  console.log('Current state:', store.getState().user);\n});\n\n// You can trigger actions and check state\n// store.dispatch({ type: 'LOGIN', payload: { name: 'NodeUser' } });\n// console.log('State after login:', store.getState().user);\n\n// To clear persisted state (useful for logout/reset)\n// persistor.purge();\n\n// This will keep the Node process alive long enough to see the output\nsetTimeout(() => {\n  console.log('Final state before exit:', store.getState().user);\n}, 1000);","lang":"typescript","description":"This example demonstrates how to set up `redux-persist-node-storage` with `redux-persist` in a Node.js environment. It defines a simple Redux store with a user reducer, configures the `AsyncNodeStorage` to save to a local directory, and initializes the persisted store, logging the rehydrated state. It also shows basic interaction and a purge option.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}