In a Newman command line, what does the `--folder` option select from a collection?
answer
- It narrows what a run executes
- A name or an id, not a path
- The CLI hands it to entrypoint.execute
- A request matches too, not only folders
- Subtree flattened in file order
basics
~10 sIn Newman, --folder narrows a run to one part of the collection: it takes the name or id of a folder or of a single request, and only that subtree executes.
solid answer
~40 s`--folder` picks the run's entry point. The CLI passes the value through as the runtime's `entrypoint.execute`, resolved by the default `idOrName` lookup: the first entry in the collection's `item` tree whose id, or failing that whose name, equals the value. Despite the option's name the lookup matches a request as well as a folder, so a value like `Create order` can run exactly one call. Whatever matches becomes the root of the run, and the engine flattens that subtree into the requests it will send, in the collection file's own order. The search takes own children before deeper ones and stops at the first match, so a top-level folder beats a same-named folder nested further down. A value matching nothing fails the run rather than running nothing.
code
bash · 2 linesnewman run collection.json --folder "Checkout"
newman run collection.json --folder "Create order"go deeper
Be ready to say plainly that --folder limits a run to one named part of the collection, and that the name or id you pass must match an entry exactly.
Explain the mechanics: the value becomes the run's entry point, is resolved by an id-or-name lookup that stops at the first match, and the matched subtree is flattened in the file's own order.
Show that you know the failure modes in a shared collection: a duplicated name selects the wrong subtree silently, a request can win the lookup, and a rename turns a working command line into a run that never starts.
Own the consequence for how teams drive one collection from many places: folder names passed on a command line are an interface, and uniqueness and rename discipline are the cheap controls that keep selection honest.
## What the option is for A saved Postman collection is one JSON document. Its `item` array holds the collection's contents, and an entry in that array is either a request or a folder carrying its own nested `item` list. A run with no selection walks the whole tree and sends every request in it. **`--folder` is the Newman command-line option that narrows a run to one part of that tree**, and it takes the **name or the id** of the thing you want to run. ## What the option becomes The CLI does not do the filtering itself. It converts the value into the run option the execution engine understands: **`entrypoint.execute`**, the single node a run starts from, together with a lookup strategy that says how the value is resolved. With one `--folder` value that strategy is the default **`idOrName`**, which resolves the value by finding an entry whose **id** or whose **name** equals it. The consequences worth memorising: - the value is compared against **ids and names**, so an id copied out of the file works exactly where a name does; - it is **equality against a single node**, not a path expression — you name one entry, never `Checkout/Payments`; - there is **no wildcard and no pattern**: a value either equals something or it matches nothing; - the **first match wins**, and the search takes **own children before deeper ones**, so a top-level entry beats a same-named entry buried further down; - a value that matches nothing is a **failure to start**, not a quiet empty run. ## Despite the name, it matches a request too The option is called `--folder`, and that name misleads in one specific way: **the lookup matches a request as well as a folder.** Requests and folders live side by side in the same `item` arrays and are resolved by the same id-or-name comparison, so a value naming a request resolves to that request and the run consists of exactly that one call. This is the quickest way to re-run a single request from a terminal, and it is also a trap, because a request that happens to share a folder's name can win the lookup. ## What actually executes Once the entry point resolves, the engine **flattens that subtree** into the ordered list of requests to send. Flattening means nested folders contribute their requests in place: a folder holding two requests and then a sub-folder of three yields five requests, the two first and the three after, because that is the order the entries occupy in the file's `item` arrays. Selection therefore changes **which** requests run and never the relative order of the ones that do. | Command line | Resolved entry point | What runs | |---|---|---| | no `--folder` | the collection itself | every request, in file order | | a value matching a folder | that folder | its subtree, flattened, in file order | | a value matching a request | that request | exactly one request | | a value matching nothing | none | nothing runs; the run fails to start | ## What it does not do - It does not **reorder** anything. Order is the position of entries in the file's `item` arrays, and selection preserves it inside the chosen subtree. - It does not **filter by pattern**. There is no substring or glob form, so "everything named like a smoke test" is not a selection this option can express. - It does not **change the sequence once a run is under way**. Jumping to a named request mid-run, or dropping the current one, is a different mechanism belonging to the sandbox's execution API rather than to selection. - It does not **detach the chosen entries from their place in the file**. Selection decides what executes; what an enclosing folder or the collection contributes to a request inside it is a separate subject. ## Why interviewers ask it Because the option looks obvious and is not. Candidates reliably assume three wrong things: that only a folder can match, that a nested folder needs a path, and that a misspelt value simply runs nothing. Being able to say **"it sets the run's entry point, resolved by id or name, first match wins, and that subtree is flattened in file order"** is the whole answer, and it explains every failure mode you will actually meet — the wrong folder ran because a name was duplicated, one request ran because a request shared a folder's name, or nothing ran at all because somebody renamed a folder in the shared collection.
- What happens when the value passed to `--folder` matches nothing in the collection?The entry point cannot be resolved, so the run fails to start rather than running nothing quietly. An empty-but-clean run would be the dangerous outcome, because it looks like success. Treat an unmatched selection as a broken command line — usually a typo, or a folder someone renamed in the shared collection since the command was written.
- Does `--folder` accept a path such as `Checkout/Payments` to disambiguate nested folders?No. The default lookup compares the value to a single entry's id or name; it is equality on one node, not a path expression, and there is no separator syntax. Nesting is disambiguated only by the traversal order — own children before deeper ones — and by the first match winning, which is exactly why duplicate names are hazardous.
saying these in an interview costs you the question
- Thinks --folder can only ever match a folder, never a request
- Expects a slash-separated path to reach a nested folder
- Believes an unmatched value simply runs nothing and passes
- Assumes --folder reorders or filters requests within the subtree
- Confuses selecting a subtree with redirecting the sequence mid-run