How to get file extension with Node.js?

Sometimes, we want to get file extension with Node.js.

In this article, we’ll look at how to get file extension with Node.js.

How to get file extension with Node.js?

To get file extension with Node.js, we can use the path.extname method.

For instance, we write

const path = require('path')

const ext = path.extname('index.html')

to call path.extname with 'index.html' to return the extension of index.html.

Conclusion

To get file extension with Node.js, we can use the path.extname method.