0
0
Node.jsframework~10 mins

path.extname for file extensions in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the 'path' module in Node.js.

Node.js
const path = require('[1]');
Drag options to blanks, or click blank then click option'
Afs
Bhttp
Cpath
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fs' instead of 'path' to import the module.
Forgetting to use quotes around the module name.
2fill in blank
medium

Complete the code to get the file extension from the filename.

Node.js
const ext = path.[1]('example.txt');
Drag options to blanks, or click blank then click option'
Abasename
Bextname
Cdirname
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'basename' which returns the filename, not the extension.
Using 'dirname' which returns the directory path.
3fill in blank
hard

Fix the error in the code to correctly get the extension of 'archive.tar.gz'.

Node.js
const extension = path.[1]('archive.tar.gz');
Drag options to blanks, or click blank then click option'
Aextname
Bbasename
Cparse
Dformat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'basename' which returns the full filename.
Using 'parse' or 'format' which are for different purposes.
4fill in blank
hard

Fill both blanks to get the extension of a file path stored in variable 'filePath'.

Node.js
const ext = path.[1]([2]);
Drag options to blanks, or click blank then click option'
Aextname
BfilePath
Cbasename
Ddirname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'basename' instead of 'extname' for the method.
Using a string literal instead of the variable name.
5fill in blank
hard

Fill all three blanks to extract the extension and check if it equals '.js'.

Node.js
const ext = path.[1](filename);
if (ext === [2]) {
  console.log('This is a JavaScript file.');
}
Drag options to blanks, or click blank then click option'
Aextname
B'.js'
C'.txt'
Dbasename
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'basename' instead of 'extname'.
Comparing to '.txt' instead of '.js'.