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
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.