I am writing a program in node.js.
I want to create a function isJsFile(file) that get a file (name or content) and return true if the file is javascript file or false if its not.
How can i create this function?
I am writing a program in node.js.
I want to create a function isJsFile(file) that get a file (name or content) and return true if the file is javascript file or false if its not.
How can i create this function?
You can to use node-mime to indentity by mime type: https://github.com/broofa/node-mime
Simply use path to get the file extension:
var path = require('path')
path.extname(YOUR_FILENAME) // returns '.js' if file is a js file