Does NestJS has built-in tools for CRUD generation - node.js

Does NestJS has built-in tools for CRUD generation like Loopback or Sails.js has? I really like the idea of NestJS but i don't want to repeat the same things in each Controller. I will be appreciative if someone could explain how can i reach it?

No, NestJS doesn't have this feature out of the box but you can use nestjsx/crud, It allows you to use all CRUD operation only by declaring an entity class. Check the getting-started page.
EDIT: now NestJS has a built in schematics, you can find a guide here on the trilon blog

Related

Type Script Decorators for Authorization in Nodejs

I am developing server side nodejs application using typescript.I have to implement authorization in my nodejs application. I was planning to use Type script "Method and Class Decorators" for the same.But below post states, "Decorators are an experimental feature that may change in future releases".
https://www.typescriptlang.org/docs/handbook/decorators.html
Can someone please suggest, what is the best cleaner way to implement authorization?
If I go with decorators, How much will future VSCode releases impact its functionality.
IMHO using decorators is fine. TypeScript will not drop them and there is also a TC39 proposal for them (currently stage 2).
If you're using the power of the internet, I am sure you'll find plenty of example that use decorators to do authentication. A quick search gave me this express lib: https://github.com/Romakita/ts-express-decorators
But you do not need to limit your search to TypeScript. People, who are using Babel, are also already using decorators.
Not quite sure what your editor (VSCode) has to do with this language feature.

Custom Model API Validation in node.js

I am creating backend apis for an application where i reauired to validate request payloads/parameters before processing and storing into my database. I am new to node.js eralier i used to validate same using using custom attributes in C# application. I want acheive same flexibility in node.js as well. What is the best approach i can go for?
Tons of thanks in advance.
You can use Joi. I use this library with hapijs, but you can use it alone or in combination with other frameworks. It's very flexible and configurable.

MVC approach in Node.js

Currently I am working on Node.js using the MVC type of model, as it is easier to segregate the code into modules.
What I am looking for is a better approach apart from MVC, so that the code can be easily debugged and understandable.
Please advise.
I've used quite a few different frameworks but I've always found Sails.js to be the best MVC Framework for Node, easy to learn and offers a lot, its basically express with a lot of middleware but they make creating Controllers, Models and what not very easy with their CLI, you can check our more here:
http://sailsjs.org/

How to add a method for all controllers in Sails.js?

I am trying to add a method available for all controllers in sailsjs, much like the blueprint methods are.
The method should also be exposed to a REST route (like /modelName/myBlueprintMethod).
How can I go about and do this?
I have seen lots of Qs for how to override the blueprint methods but what i need is extend the blueprint.
A little context.
What I want to achieve is to expose the schema of the model related to the controller to automate some front-end CMS.
Thanks
I also wanted a similar solution, although it would be a subset of your question: Asked a question here.
One way to go about this (and there could be others) is:
Make a service, send it the parameters and use it in all controllers.
Hope this helps.
I did mine as described here: OVERRIDE CRUD BLUEPRINTS.
I created the blueprint hooks in /api/blueprints/...

Combining SailsJS and EmberJS (routing)

I've been using SailsJS for a while now and find it a perfect REST API solution. I'm currently building an app for both Web & Mobile (native) so I need the REST part of SailsJS. I want to build a frontend for my API right now, and I found EmberJS which looks like a promising framework. I've a question about combining those two, they both have their own Routing system, and SailsJS seems to overrule Ember's one.
My guesses would be:
The most easy approach looks like building Sails in a subdirectory
eg. /api/ but I think that's not the nicest way to get this fixed.
I could choose one framework for routing and let the other delegating it's routes. For example passing parameters from SailsJS through EmberJS
How can I use those together correctly?
Think of your backand as something you can't control, like a 3rd party API. The reason is that the optimal routing for a user may differ greatly from what's considered to be good API semantics. It's also not easy to share the route declarations, but it's not a good practice anyway.
My advice:
Use ember-cli to build the frontend. It's a great tool, you'll enjoy it a lot.
Build your Sails-based API in a different repository, using the /api namespace for your API endpoints.
Try to follow the JSON API standard as closely as possible. That'll make easier to connect your backend & frontend, as most data libraries (Ember Data for eg.) tries to adhere those standards as well.
Watch Luke Melia's excellent guide on lighning fast deployment. It'll be the same concept for you but in Sails intead of Ruby/Rails.
All in all, I think if you'll have a great dev experience if you do roughly what I've outlined above. Happy coding!

Resources