UNPKG

@supernick135/face-scanner-client

Version:

Node.js client library for ZKTeco face scanning devices integration with comprehensive API support

79 lines (67 loc) • 2.62 kB
/** * Basic Usage Example - Face Scanner API Client * This example shows basic usage of the Face Scanner API client library */ const { FaceScannerClient } = require('../lib'); async function basicUsageExample() { console.log('šŸ”¬ Face Scanner API - Basic Usage Example'); // 1. Create client instance const client = new FaceScannerClient({ baseURL: 'http://localhost:9999', apiKey: 'your-api-key-here', // Replace with your actual API key timeout: 30000 }); try { // 2. Test connection console.log('\nšŸ“” Testing connection...'); const connectionTest = await client.testConnection(); if (!connectionTest.success) { console.error('āŒ Connection failed:', connectionTest.message); return; } console.log('āœ… Connected successfully'); // 3. Get system health console.log('\nšŸ„ Getting system health...'); const health = await client.getSystemHealth(); console.log('System status:', health.status); console.log('Uptime:', Math.floor(health.uptime), 'seconds'); // 4. Get devices console.log('\nšŸ“± Getting devices...'); const devices = await client.getDevices(); console.log(`Found ${devices.length} devices:`); devices.forEach(device => { console.log(` - ${device.name} (${device.id}): ${device.status}`); }); // 5. Get scanner status console.log('\nšŸ“· Getting scanner status...'); const scannerStatus = await client.getScannerStatus(); console.log('Scanner status:', scannerStatus); // 6. Get recent scans console.log('\nšŸ“Š Getting recent scans...'); const recentScans = await client.getScans({ limit: 5 }); console.log(`Found ${recentScans.length} recent scans:`); recentScans.forEach(scan => { console.log(` - Scan ${scan.id} from device ${scan.deviceId} at ${scan.timestamp}`); }); // 7. Get system statistics console.log('\nšŸ“ˆ Getting system statistics...'); const stats = await client.getSystemStats(); console.log('System stats:', stats); } catch (error) { console.error('āŒ Error:', error.message); console.error('Details:', error.response?.data || error); } } // Run the example if (require.main === module) { basicUsageExample() .then(() => { console.log('\nšŸŽ‰ Basic usage example completed!'); process.exit(0); }) .catch(error => { console.error('\nšŸ’„ Example failed:', error.message); process.exit(1); }); } module.exports = { basicUsageExample };