I'm trying to decide between two folder structures for my Node.js TypeScript project. Here are the options I've come up with:
**Option A**
```
root/
├── src/
├── tests/
├── package.json
├── tsconfig.json
```
**Option B**
```
root/
├── src/
│ ├── tests/
├── package.json
├── tsconfig.json
```
Which structure do you think is better and why? Also, when working with multiple directories that contain TypeScript files, should I use `rootDir` or `rootDirs` in my `tsconfig.json`?
5 Answers
Ultimately, I think going with Option A helps keep tests distinct from production code, but really, it's all about personal preference. Choose what suits your workflow best, and don’t stress too much about it.
Yeah! And if you're debating between directory structures, also think about how cohesive your team’s testing practices are.
Honestly, anyone can argue about folder structure, but what really matters is that you choose a format that fits your team’s workflow. Here’s a thought:
- If you're using build tools, consider how close your tests are to your production code to avoid accidentally bundling them together.
- For larger projects, you might find it useful to separate types of tests (unit vs e2e) into different directories for clarity.
That's a good point! Separating test types can really help keep the project organized as it scales.
Yes, and it also makes it easier for the CI/CD processes to manage different tests.
Folder structure debates can get intense, but really, it’s about what’s easier for you all as developers. As long as everyone on the team understands it and can find their way around, you're golden! Test positioning is subjective too. Just figure out your group’s style and stick to it.
Couldn’t agree more. If you find what clicks well with your team, just go with it!
Plus, consistency matters more than the actual structure itself.
Personally, I prefer putting my tests next to the components they’re testing. For example:
- ComponentA.ts
- ComponentA.test.ts
This way, it's much easier to navigate as your project grows and you can quickly switch between logic and tests without searching around.
True, but for end-to-end (E2E) tests, I like keeping those in a separate root folder to avoid clutter.
I think it depends on how you structure your project overall. If you have a well-organized structure, having tests next to components makes sense.
I’d lean towards Option A. I like keeping my tests separate from the production code just to keep things clean. Also, many developers agree that it helps prevent clutter in the main source folder.
But how do you config `tsconfig.json` then? It only allows specifying one directory under `rootDir`, right?
Exactly, that’s why knowing how to set it up properly is key. It's all about your project's needs!

Exactly! Just make sure it's logical for you and your team.