Node.js - File System get file type, solution around year 2012 Node.js - File System get file type, solution around year 2012 javascript javascript

Node.js - File System get file type, solution around year 2012


There is a helper library for looking up mime types https://github.com/broofa/node-mime

var mime = require('mime');mime.getType('/path/to/file.txt');         // => 'text/plain'

But it still uses the extension for lookup though


Have a look at the mmmagic module. It is a libmagic binding and seems to do exactly what you want.


You should have a look at the command line tool file (Linux). It attempts to guess the filetype based on the first couple of bytes of the file. You can use child_process.spawn to run it from within node.