node.jstypescriptarchitecturenestjsarchitectural-patterns

NestJS: where to place a file reader?


I have an architectural question regarding NestJS. Let's say I have a ContentModule and a BlueprintModule, both need to read json files. In both cases I would have a service that calls the repository which than should read those files. This repository should now use something like a FileReader class.

Where would i place this in NestJS? Should I create a new module for this and inject it into the ContentModule and BlueprintModule? I am a bit confused because I see this more as a util than a feature module. Should I just create a simple class in a utils or lib folder?

Would I create a repository at all if I don't have a database and instead access a JsonService from my BlueprintService and ContentService?

Any thoughts?


Solution

  • You can create a simple class in Utils and inject to your Contentmodule and Blueprint module.

    There is no hard and strict rule to this. You can start off by adding it in a libs and then as you find more use cases you can always move it to another module.

    Basic rule is, if you are not sure where things are to be placed, they get placed in libs. :)

    Thanks