Installation and Configuration
This section guides you through the process of installing and configuring OSI in your application.
Installation
1. Install OSI On-Premises Package
Install the OSI on-premises package using npm:
npm install osi.onpremises
2. Add TypeScript Configuration
Add the following to your tsconfig.json:
{
"compilerOptions": {
"types": ["osi.onpremises"]
}
}
Configuration
- Node.js Environment
- Electron Environment
1. Basic Setup
In your main file (e.g., index.ts), import and initialize OSI:
import { fs, Process, EventWatcher, os, db } from 'osi.onpremises';
// The modules named with lowercase characters are automatically initialized as singletons, so no need to initialized. Others are not.
2. TypeScript Configuration
Ensure your tsconfig.json includes the necessary compiler options:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
1. Main Process Setup
In your main process file (e.g., main/index.ts), import and initialize OSI:
import { fs, Process, EventWatcher, os, db } from 'osi.onpremises';
// The modules named with lowercase characters are automatically initialized as singletons, so no need to initialized. Others are not.
2. TypeScript Configuration
Ensure your tsconfig.json includes the necessary compiler options:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
3. Electron Configuration
Update your Electron main process configuration to ensure proper security settings:
import { app, BrowserWindow } from 'electron';
app.whenReady().then(() => {
const win = new BrowserWindow({
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
});
Security Considerations
-
Main Process Usage (Electron Only)
- OSI modules should only be used in the main process
- Never expose OSI directly to the renderer process
-
IPC Communication (Electron Only)
- Use IPC (Inter-Process Communication) to communicate between renderer and main processes
- Implement proper validation for all IPC messages
-
Error Handling
- Implement proper error handling for all OSI operations
- Use try-catch blocks for async operations
Next Steps
Now that you have installed and configured OSI, proceed to the First Application section to learn how to use OSI in your project.