I have to use the database of the A module in the B module and the database of B module in the A module is there a proper way to implement this without getting a circular dependency?
I can assume that if you have some modules that are uses each other, it's better to introduce new module that will have common features for both modules and import this module as a dependency. Or without module. Just create a service and make custom useFactory for it to make nestJS know what are you doing with this service.
But more precise answer in the link.
Avoiding circular dependencies the right way - NestJS
Related
Is it possible to modularize a node js application like namespacing in C# that when I import some namespace I do not have access to its internal members?
For example suppose I have three modules, module A, B, and C. Only module B uses module A export, so I want to package A and B and only export module B export.
If it's not possible, is there any transpiler, library or any other tool that can do it for me?
You need to change the architecture you are using. Check out Uncle Bob's clean architecture.
Check it out here:
http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
This architecture will allow you to write independent modules and just inject required modules anywhere as dependencies.
I'm writing a Node.js library that needs to import modules written by the user. If the user writes a module in Typescript he needs to transpile it into Javscript before feeds it into the library. I want to go one step further and make the library compatible with typescript modules in a transparent way. I can transpile the mdoule in os.tempdir(), read it into memory and delete it. It is a three step solution but i thought may be there is a more direct way.
What is the proper way of adding a new Module in Sailsjs?
I understand I can just "npm install" a new module and "require" it in the pages I want to use it - but I believe there is a better way of doing that without having to repeatedly "require" the new module everywhere...
Well, this is the proper way of adding modules within your code. Your code becomes easier to maintain when you explicitly use require(), where you need it.
However, you can also make a module globally available. Check out this answer to find out how to do this and why you shouldn't be doing this.
Didn't see any definitive instructions for this on the web. I'm looking for a familiar way to include those modules in my project. For example by including them in the app.module.ts file and then importing them in the relevant components.
It Depends on the Place where the module is used. For Example if it is used in a particular module you can import that in respective module instead of doing that in app.module. This will eliminate the initial loading of the time and it will be much effective if you use lazy loading kind of things.
If that is used throughout the application you can create a shared module where you can import and export these type of third party and common components, directives etc.
I have a question around the dependency injection based on AngularJS and NodeJS.
There's any difference between $injector from AngularJS and the require module from NodeJS?
Would be nice use require module with a MEAN STACK architecture instead $injector for the Angular app? And for whar propose?
They're quite different.
Angular's $injector is a classic example of Inversion of contorl. Instead of each module fetching their dependencies, you have an $injector whose job it is to provide dependencies to the modules that are asking for them at run-time. This makes it really to easy switch out the dependencies in tests for example, since nothing is forcing you to pass in the expected dependency -- you could pass in a mock version.
NodeJS's require methods just allow you to require other javascript files and have access to any properties they set on module.exports.
They're not mutually exclusive. You could use browserify (nodejs like require for the front-end) to load the different Angular modules if they are in separate files. It would essentially be equivalent to concatenating them, however. If you wanted to dynamically load the angular modules as needed, you would have to use something like RequireJs.
Conversely, you can use inversion of control in node by passing stuff into a module rather than trying to fetch it from the module. It's actually good practice in many cases.