Detect the programming language of any file.

Language Detect

Detect the programming language of any file by checking the file name, file extension, file shebang and falling back to a programming language classifier. For more language information, it should be used in conjunction with language-map.

npm install language-detect --save
var detect = require('language-detect');
detect(__dirname + '/test.js', function (errlanguage) {
  console.log(err);      //=> null 
  console.log(language); //=> "JavaScript" 
detect.sync(__dirname + '/test.js'); //=> "JavaScript" 
detect.contents(__dirname + '/test.js', 'var test = true;\n'); //=> "JavaScript" 
detect.filename(__dirname + '/test.js'); //=> "JavaScript" 
detect.shebang('#!/usr/bin/env node\n...'); //=> "JavaScript" 

Uses language-classifier which can only detect a small subset of languages.

detect.classify('.test { color: red; }')
  • detect.aliases A map of known aliases
  • detect.interpreters A map of known interpreters
  • detect.extensions A map of known file extensions
  • detect.filenames A map of known file names