From the course: TypeScript for Node.js Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use decorators into Node.js

Use decorators into Node.js

From the course: TypeScript for Node.js Developers

Start my 1-month free trial

Use decorators into Node.js

- [Narrator] Decorators are a powerful tool to use in your code, and if you have any experience coding in Angular, you know what they are. In its simplest definition, decorators are a way to wrap a piece of code around another function or class. Let's take a look at how you'd implement a decorator in your code. If you want to see examples of how decorators are used, look no further than Angular's documentation or the framework. If you look into the documentation, and click on Dependency Injection and go to Angular Dependency Injection, you're going to see an example here where actually implementing a decorator here. This decorator has been imported from the angular//core code and now it's being implemented in this section here. We're passing some metadata inside of the component which is a decorator, but how would you do this in actual code? Let's switch to VS code and do one for an example. Create a new file. We'll call this one decorator example dot ts and what we're going to do is…

Contents