A JavaScript library for interacting with ZK Time & Attendance devices.
npm i zklib-jsconst ZKLib = require('node-zklib')
async function test() {
let zkInstance = new ZKLib('192.168.1.201', 4370, 5200, 5000);
try {
// Create socket to machine
await zkInstance.createSocket()
// Get general info
console.log(await zkInstance.getInfo())
// Get users in machine
const users = await zkInstance.getUsers()
console.log(users)
// Get attendance logs
const logs = await zkInstance.getAttendances()
console.log(logs)
// Disconnect
await zkInstance.disconnect()
} catch (e) {
console.log(e)
}
}
test()createSocket(): Establish connection with the devicegetInfo(): Get general device informationgetUsers(): Retrieve users from the devicesetUser(uid, userid, name, password, role = 0, cardno = 0): Create a new usergetAttendances(callback): Get all attendance logsgetRealTimeLogs(callback): Get real-time logsgetTime(): Get current time from the devicegetSerialNumber(): Get device serial numbergetFirmware(): Get firmware versiongetPIN(): Get device PINgetFaceOn(): Check if face recognition is enabledgetSSR(): Get Self-Service-Recorder statusgetDeviceVersion(): Get device versiongetDeviceName(): Get device namegetPlatform(): Get platform versiongetOS(): Get OS versiongetWorkCode(): Get work codegetAttendanceSize(): Get attendance log sizeclearAttendanceLog(): Clear attendance logsdisconnect(): Disconnect from the device
You can execute custom commands using the executeCmd function:
async executeCmd(command, data='') {
return await this.functionWrapper(
() => this.zklibTcp.executeCmd(command, data),
() => this.zklibUdp.executeCmd(command, data)
)
}
// Example: Unlock the door
zkInstance.executeCmd(CMD.CMD_UNLOCK, '')For more commands, refer to the ZK protocol documentation.
This library is based on:
Contributions are welcome! Please feel free to submit a Pull Request.