Categories
JavaScript Answers

How to get file extension with Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *