0
0
Node.jsframework~5 mins

path.extname for file extensions in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does path.extname do in Node.js?

path.extname returns the file extension part of a file path as a string, including the dot.

Click to reveal answer
beginner
How does path.extname('index.html') evaluate?

It returns '.html' because that is the extension of the file name.

Click to reveal answer
intermediate
What will path.extname('archive.tar.gz') return?

It returns '.gz' because extname only returns the last extension after the last dot.

Click to reveal answer
intermediate
What does path.extname('folder/.hiddenfile') return?

It returns an empty string '' because the file starts with a dot but has no extension after it.

Click to reveal answer
beginner
Why is path.extname useful when working with files?

It helps you find out the type of a file by its extension, so you can decide how to handle or process it.

Click to reveal answer
What does path.extname('photo.jpeg') return?
A'photo'
B'.jpeg'
C'.photo'
D'' (empty string)
If a file name is '.env', what does path.extname('.env') return?
Anull
B'.env'
C'.env' without dot
D'' (empty string)
Which part does path.extname return from 'archive.tar.gz'?
A'.gz'
B'.tar.gz'
C'.tar'
D'archive'
What will path.extname('folder/file') return if the file has no extension?
A'' (empty string)
Bnull
C'.folder'
D'.file'
Why should you use path.extname instead of string methods to get file extensions?
AIt deletes the extension from the file name.
BIt changes the file extension automatically.
CIt handles edge cases like hidden files and multiple dots correctly.
DIt only works with .txt files.
Explain how path.extname works and give an example of its output.
Think about what part of a file name it extracts.
You got /3 concepts.
    Describe a situation where path.extname might return an empty string.
    Consider files without a dot after the name.
    You got /3 concepts.