asked in NodeJS by (0 points)
How to get original extension file?

actually it can validate by extension on filename, but how if the extension on filename changed?

ex :

original filename -> this-file.json

the filename changed to -> this-file.jpg

is possible to validate that this-file.jpg is json?

1 Answer

answered by (0 points)

You can get the original extension by use : path.extname(); function
Here the example code :

var path = require('path');
var fileName = 'this-file.json';

console.log(path.extname(fileName)); // the result should be .json

...