Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get filesystem type with node js

I'm working on a project in node js and I need to get the file system type of a disk i.e., I want to know if it's FAT or NTFS etc... Is there any way I can accomplish this with node js? Any help is appreciated . Thanks.

like image 465
Shiva Teja Avatar asked Oct 20 '17 16:10

Shiva Teja


People also ask

Is fs included in node?

fs it's a native node. js module, you don't need install it.

What is use of fs in node JS?

Node. js includes fs module to access physical file system. The fs module is responsible for all the asynchronous or synchronous file I/O operations.

Can I use fs in JavaScript?

With Node. js, you can programmatically manipulate files with the built-in fs module. The name is short for “file system,” and the module contains all the functions you need to read, write, and delete files on the local machine.

Where is fs module in node JS?

The Node.js file system module allows you to work with the file system on your computer. To include the File System module, use the require() method: var fs = require('fs');


1 Answers

As you didn't specify target machine's operating system, you can use such command under Windows:

fsutil fsinfo volumeinfo <disk letter here>:

to show output simillar to this one:

H:\>fsutil fsinfo volumeinfo c:

Volume Name :
Volume Serial Number : 0x4c31bcb3
Max Component Length : 255
File System Name : NTFS
Supports Case-sensitive filenames
Preserves Case of filenames
Supports Unicode in filenames
Preserves & Enforces ACL's
Supports file-based Compression
Supports Disk Quotas
Supports Sparse files
Supports Reparse Points
Supports Object Identifiers
Supports Encrypted File System
Supports Named Streams

You need only to parse command output correctly. I would recommend you storing filesystem names in array and seeking for every in command output excluding first line. This way you can be sure which filesystem is used by target machine.

Here you have code to print what does this command output to your commandline:

const { exec } = require('child_process');
exec('fsutil fsinfo volumeinfo c:', (err, stdout, stderr) => {
  if (err) {
    // node couldn't execute the command
    return;
  }

  // the *entire* stdout and stderr (buffered)
  console.log(`stdout: ${stdout}`);
});

This is untested code, I really think that you want to write own snippet. I can't decide will this code work because I have no opportunity now.

Also, why would you check filesystem used?

like image 171
Kamila Szewczyk Avatar answered Oct 22 '22 19:10

Kamila Szewczyk