Complete the code to parse a file path into its parts using path.parse.
const path = require('path'); const parsed = path.[1]('/home/user/file.txt'); console.log(parsed);
The path.parse method breaks a file path into its parts like root, dir, base, ext, and name.
Complete the code to create a path string from an object using path.format.
const path = require('path'); const obj = { root: '/', dir: '/home/user', base: 'file.txt' }; const fullPath = path.[1](obj); console.log(fullPath);
The path.format method builds a path string from an object with parts like root, dir, base, etc.
Fix the error in the code to correctly parse the path '/var/log/sys.log'.
const path = require('path'); const parts = path.[1]('/var/log/sys.log'); console.log(parts.ext);
To get parts of a path, use path.parse. Using format or others will cause errors or wrong results.
Fill both blanks to parse a path and then format it back to a string.
const path = require('path'); const parsed = path.[1]('/etc/nginx/nginx.conf'); const formatted = path.[2](parsed); console.log(formatted);
First, use parse to split the path, then format to join it back into a string.
Fill all three blanks to parse a path, change its base, and format it back.
const path = require('path'); const parsed = path.[1]('/usr/local/bin/script.sh'); parsed.base = '[2]'; parsed.name = '[3]'; const newPath = path.format(parsed); console.log(newPath);
Use parse to get parts, then change base and name, and finally format to build the new path.