0
0
Node.jsframework~5 mins

path.resolve for absolute paths in Node.js - Cheat Sheet & Quick Revision

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

path.resolve() creates an absolute path by combining given path segments. It starts from the right and works left until it finds an absolute path or the root.

Click to reveal answer
beginner
How does path.resolve() handle relative paths?

If no absolute path is found in the arguments, path.resolve() uses the current working directory as the base to create an absolute path.

Click to reveal answer
intermediate
What is the difference between path.resolve() and path.join()?

path.resolve() returns an absolute path, resolving '..' and '.' segments and starting from the root or current directory. path.join() just concatenates paths and normalizes them but may return a relative path.

Click to reveal answer
intermediate
Example: What is the output of path.resolve('foo', '/bar', 'baz')?

The output is /bar/baz. Because /bar is an absolute path, path.resolve() ignores foo and starts from /bar.

Click to reveal answer
beginner
Why is path.resolve() useful in Node.js projects?

It helps create absolute paths safely, avoiding errors from relative paths. This is important when working with files or modules to ensure paths are correct regardless of where the script runs.

Click to reveal answer
What does path.resolve() return if no absolute path is given in arguments?
AAn absolute path based on current working directory
BA relative path concatenated from arguments
CAn error
DThe first argument unchanged
Which method returns an absolute path in Node.js?
Aconsole.log()
Bpath.join()
Cfs.readFile()
Dpath.resolve()
Given path.resolve('a', 'b', '/c'), what is the output?
A/a/b/c
B/c
Ca/b/c
Da/b
What does path.resolve() do with '.' and '..' in paths?
ALeaves them as is
BRemoves all dots
CResolves and normalizes them
DThrows an error
Why prefer path.resolve() over manual string concatenation for paths?
AIt handles different OS path formats and normalizes paths
BIt runs faster
CIt encrypts paths
DIt only works on Windows
Explain how path.resolve() creates an absolute path from given segments.
Think about how it builds the path step by step.
You got /4 concepts.
    Describe the difference between path.resolve() and path.join() in Node.js.
    Focus on the output type and path processing.
    You got /4 concepts.