[Node.js] Getting File Extensions with path.extname

Tadashi Shigeoka ·  Mon, April 21, 2014

Using Node.js’s path module, you can get file extensions as follows:

path.extname('index.html')
// returns
'.html'

path.extname('index.coffee.md')
// returns
'.md'

path.extname('index.')
// returns
'.'

path.extname('index')
// returns
''

Reference Information

Path Node.js v0.10.26 Manual & Documentation

That’s all from the Gemba.