Installation
Prerequisites
- Node.js 24.13.0 or higher
- TypeScript 5.0 or higher (optional but recommended)
- Capacitor 8.0 or higher (for mobile platforms; Android minSdk 23 — secure storage requires API 23+)
Package Installation
Using npm
npm install strata-storage
Using yarn
yarn add strata-storage
Quick Setup
The easiest way to get started is using our configuration wizard:
npx strata-storage configure
This interactive CLI will:
- Detect your project type (React, Vue, Angular, etc.)
- Configure storage options
- Generate configuration files
- Create example code
- Install necessary dependencies
Manual Setup
1. Basic Configuration
Create a strata.config.js file:
export default {
// Default storage types in order of preference
defaultStorages: ['indexedDB', 'localStorage', 'memory'],
// Enable features as needed
encryption: {
enabled: true,
password: process.env.STRATA_ENCRYPTION_KEY
},
compression: {
enabled: true,
threshold: 1024 // Only compress if > 1KB
},
sync: {
enabled: true
},
ttl: {
defaultTTL: 3600000, // 1 hour
autoCleanup: true
}
};
2. TypeScript Configuration
Add to your tsconfig.json:
{
"compilerOptions": {
"types": ["strata-storage"],
"paths": {
"strata-storage": ["node_modules/strata-storage/dist"],
"strata-storage/*": ["node_modules/strata-storage/dist/*"]
}
}
}
3. Framework-Specific Setup
React
import { StrataProvider } from 'strata-storage/react';
import config from './strata.config';
function App() {
return (
<StrataProvider config={config}>
<YourApp />
</StrataProvider>
);
}
Vue 3
import { createApp } from 'vue';
import { StrataPlugin } from 'strata-storage/vue';
import config from './strata.config';
const app = createApp(App);
app.use(StrataPlugin, config);
Angular
import { StrataModule } from 'strata-storage/angular';
import config from './strata.config';
@NgModule({
imports: [
StrataModule.forRoot(config)
]
})
export class AppModule {}
Platform-Specific Setup
Capacitor (iOS/Android)
- Install Capacitor if not already installed:
npm install @capacitor/core @capacitor/cli
npx cap init
- Add platforms:
npx cap add ios
npx cap add android
- Sync the plugin:
npx cap sync
iOS Additional Setup
For Keychain access, add to Info.plist:
<key>NSFaceIDUsageDescription</key>
<string>Store secure data with biometric protection</string>
Android Additional Setup
For encrypted storage, ensure minimum SDK version in android/variables.gradle:
ext {
minSdkVersion = 23
}
Firebase (optional cross-device sync)
Firebase is an optional peer dependency — install it only if you use the Firebase sync feature:
npm install firebase
import { enableFirebaseSync } from 'strata-storage/firebase';
Environment Variables
For sensitive configuration, use environment variables:
# .env
STRATA_ENCRYPTION_KEY=your-secret-key
STRATA_DEFAULT_STORAGE=indexedDB
STRATA_SYNC_ENABLED=true
Then in your config:
export default {
encryption: {
enabled: true,
password: process.env.STRATA_ENCRYPTION_KEY
},
defaultStorages: [process.env.STRATA_DEFAULT_STORAGE || 'memory']
};
Build Configuration
Webpack
No special configuration needed - Strata Storage is zero-dependency.
Vite
Add to vite.config.js if using SSR:
export default {
ssr: {
noExternal: ['strata-storage']
}
};
Next.js
For server-side rendering, initialize only on client:
import dynamic from 'next/dynamic';
const StrataProvider = dynamic(
() => import('strata-storage/react').then(mod => mod.StrataProvider),
{ ssr: false }
);
Verify Installation
Create a test file to verify everything is working:
import { Strata } from 'strata-storage';
async function test() {
const storage = new Strata();
await storage.initialize();
await storage.set('test', { message: 'Hello Strata!' });
const value = await storage.get('test');
console.log('Success:', value);
}
test().catch(console.error);
Next Steps
Troubleshooting
Module Resolution Issues
If you encounter module resolution issues:
- Clear node_modules and reinstall:
rm -rf node_modules package-lock.json
npm install
- Check TypeScript paths configuration
- Ensure you're importing from the correct path
Platform-Specific Issues
- iOS: Run
npx cap sync iosafter installation - Android: Run
npx cap sync androidafter installation - Web: Ensure your bundler supports ES modules
For more help, see our troubleshooting guide or open an issue.