libgio-node is a native Node addon (N-API + GLib/GIO) focused on Linux file and mount operations.
- Linux only.
- Designed for Electron and Node.
- This module can modify and delete files. Use with care.
sudo apt install libgio-2.0-dev
```bash
npm i libgio-node
constgio=require('libgio-node');importgiofrom'libgio-node';The ESM entry exports a default object. Use default import style for ESM.
- Added ESM support via package exports.
- ESM consumers should use default import:
The addon currently exports:
ls(pathOrUri, callback)get_file(pathOrUri)get_file_icon(pathOrUri)get_file_icon_path(pathOrUri)cp(src, dest, overwriteFlag?)cp_async(src, dest, callback)cp_cancel(handle)mkdir(pathOrUri)mv(src, dest, progressCallback?)rm(pathOrUri)rm_async(pathOrUri, callback)rm_cancel(handle)mount(driveName, callback)umount(target, callback)monitor(callback)open_with(pathOrUri)du(pathOrUri)count(pathOrUri)disk_stats(pathOrUri)watch(pathOrUri, callback)stop_watch(pathOrUri)exec(command, callback)set_execute(pathOrUri)clear_execute(pathOrUri)exists(pathOrUri)get_drives(callback)get_mounts(callback)connect_network_drive(host, port, username, password, ssh_key, type, callback)find(query, callback)find(query, sourcePath, callback)find(query, options, callback)find(query, sourcePath, options, callback)
gio.ls("/tmp",(err,files)=>{if(err){console.error("ls error:",err);return;}console.log(files);});try{constfile=gio.get_file("/tmp/example.txt");console.log(file.name,file.size,file.is_dir);}catch(err){console.error(err);}try{consticon=gio.get_file_icon("/tmp/example.txt");console.log(icon.icon,icon.names);}catch(err){console.error(err);}try{consticonPath=gio.get_file_icon_path("/tmp/example.txt");console.log(iconPath.icon_path,iconPath.symbolic_icon_path);}catch(err){console.error(err);}try{gio.cp("/tmp/a.txt","/tmp/b.txt",1);// overwriteFlag=1}catch(err){console.error(err);}constcopyHandle=gio.cp_async("/tmp/a.bin","/tmp/b.bin",(err,data)=>{if(err){console.error("copy failed/cancelled:",err);return;}// Progress callback payloadif(!data.completed){console.log("progress",data.current_num_bytes,data.total_bytes);return;}// Completion payloadconsole.log("copy completed");});// Later:// gio.cp_cancel(copyHandle);try{gio.rm("/tmp/b.txt");}catch(err){console.error(err);}constrmHandle=gio.rm_async("/tmp/big-file.bin",(err,ok)=>{if(err){console.error("rm failed/cancelled:",err);return;}console.log("removed:",ok);});// Later:// gio.rm_cancel(rmHandle);try{gio.mv("/tmp/src.txt","/tmp/dst.txt",(err,data)=>{if(!err)console.log("mv progress",data);});}catch(err){console.error(err);}gio.watch("/tmp",(event)=>{console.log(event.event,event.filename);});// Later:// gio.stop_watch("/tmp");gio.monitor((name)=>{console.log("device/mount event:",name);});gio.get_drives((err,drives)=>{if(!err)console.log(drives);});gio.get_mounts((err,mounts)=>{if(!err)console.log(mounts);});gio.mount("MyDriveName",(err,msg)=>{if(err)console.error(err);elseconsole.log(msg);});gio.umount("/run/user/1000/gvfs/smb-share:server=host,share=data",(err,msg)=>{if(err)console.error(err);elseconsole.log(msg);});gio.connect_network_drive("server.local",// host22,// port"user",// username"pass",// password0,// ssh_key flag"smb",// type: smb or ssh(err,data)=>{if(err){console.error(err);return;}console.log(data);});console.log(gio.exists("/tmp"));console.log(gio.du("/tmp"));console.log(gio.count("/tmp"));console.log(gio.disk_stats("/tmp"));gio.exec("ls -la /tmp",(err,lines)=>{if(!err)console.log(lines);});gio.open_with("/tmp/example.pdf");gio.set_execute("/tmp/script.sh");gio.clear_execute("/tmp/script.sh");gio.find("report",(err,results)=>{if(!err)console.log(results);});gio.find("report","/home/user/Documents",(err,results)=>{if(!err)console.log(results);});gio.find("report","/home/user/Documents",{minSize: 1024,maxSize: 10*1024*1024,dateFrom: "2026-01-01T00:00:00Z",dateTo: newDate(),},(err,results)=>{if(!err)console.log(results);});find uses Tracker when available and falls back to recursive GIO filesystem search when Tracker is unavailable or returns no matches.
- Error style is mixed in the current native implementation.
- Some APIs pass string errors (
"..."), while others may passErrorobjects. - Most success callbacks follow
(null, data).
npm run buildVersion: 1.0.7