javascriptnode.jsexfat

Format a drive in node.js


I'm working on a project in node.js and I'm stuck at this. I need to convert an external device ( a usb stick etc.) into an "exFAT" partition if it's not an exFAT . I used an npm package called "drivelist-scanner" to get the list of usb devices connected and also their mountpoints. Now the only thing left to do is to convert them into exFAT and I don't know how to do it. I came across an npm package called "gpt" which said it can format drives but the documentation is not so clear. Here's a link to the github repository for gpt : Github link

Any ideas on how to accomplish this? I'm even willing to launch a script based on the operating system to do the job, but I'm not sure on how to do this too. Any help is appreciated. Thanks.


Solution

  • Actually you can not directly format a drive with programming languages. You will need to invoke a operating system specific program to do the actual work for you.

    Create a bash script

    You can use this info for do that.

    https://superuser.com/questions/274687/how-do-i-format-a-usb-drive-on-a-pc-that-was-formatted-on-a-mac

    Run a bash script with node.js

    You can use exec command for run a bash script with node.js

    Run shell script with node.js (childProcess)