Amazing Backends for Angular Devs with NestJS with Ely Lucas - AiA 400

Ionic’s very own Ely Lucas swings by to chat to Alyssa, Chris & Brooks about NestJS, the node framework that’s winning over devs in the Angular community and beyond. The panel dive into the docs, learning about how Nest allows developers to structure powerful backends with a syntax that will make Angular devs in particular feel right at home.

Special Guests: Ely Lucas

Show Notes

Ionic’s very own Ely Lucas swings by to chat to Alyssa, Chris & Brooks about NestJS, the node framework that’s winning over devs in the Angular community and beyond. The panel dive into the docs, learning about how Nest allows developers to structure powerful backends with a syntax that will make Angular devs in particular feel right at home.

Sponsors

Links

Picks

 

Transcript

 
ALYSSA_NICOLL: Hello and howdy everyone. Welcome to another Adventures in Angular. My name is Alyssa Nykle and today with us on the panel, we have Chris Ford. 

CHRIS_FORD: Hello from the heat death of the universe. 

ALYSSA_NICOLL: I hear it's warm in the UK right now. 

CHRIS_FORD: Just a touch. 

ALYSSA_NICOLL: We also have with us Brooks Orsipp. 

BROOKS_FORSYTH: Hello. 

CHRIS_FORD: Hi. 

ALYSSA_NICOLL: I'm like waving. 

BROOKS_FORSYTH: Oh, it's so. Mate, it's great, great audio, doesn't it? Yeah, it does. I'm waving. I'm waving back.

ALYSSA_NICOLL: And gentlemen today with us, our guest of honor, man of the hour, Eli Lucas. Welcome to the show, Eli. 

ELY_LUCAS: Hi everybody from hot and smoky Denver, Colorado. 

ALYSSA_NICOLL: Smoky. 

ELY_LUCAS: Yeah. We got a, we got a forest fire going on. So we've got a bunch of smog and stuff in the air. I figured the first half of 2020 tried to fatten us up and now it's trying to smoke us. So It's just what you want, isn't it? When it's hot weather. Does anyone watch Hannibal? 

ALYSSA_NICOLL: I have it. But the way you described that, I was like, kind of sounds like beef jerky. So it could be the weather. It could be a smoked meat, you know? 

ELY_LUCAS: Right. 

ALYSSA_NICOLL: Is Hannibal related to this, Brooks? What were you saying? 

ELY_LUCAS: Oh, well, if you're eating people, I mean, it's a cannibal. 

ALYSSA_NICOLL: Oh, right. 

ELY_LUCAS: Smoking human meat. 

Hey, folks, this is Charles Maxwell. I've been talking to a whole bunch of people that want to up date their resume and find a better job. And I figure, well, why not just share my resume? So if you go to topendevs.com slash resume, enter your name and email address, then you'll get a copy of the resume that I use, that I've used through freelancing, through most of my career, as I've kind of refined it and tweaked it to get me the jobs that I want. Like I said, topendevs.com slash resume will get you that. And you can just kind of use the formatting. It comes in Word and Pages formats and you can just fill it in from there. 

ALYSSA_NICOLL: So Eli, tell us a bit about yourself, who you are, where you work. 

ELY_LUCAS: Yep. I'm a software developer. I've been doing this gig now for a little over 20 years and I work at a pretty awesome company called Ionic, which you might've heard of before. Yeah. But you know, today though, I'm not, I'm not here to talk about Ionic. I'm here to talk about a little something else. 

ALYSSA_NICOLL: Tell us, tell us Eli, what are we talking about on today's show?

ELY_LUCAS: So today we're going to dive into an SJS a little bit. And before I actually start talking about SJS, I'm going to give a little story about like how I ran into it and where I find it's very about valuable. And so if you think about it, we got this like unicorn title out there in software development called the full stack developer, right? And to me it's like, well, what, what does like full stack development mean? And it's kind of like where you're pretty confident on being able to work on both the front end of the application and the back end of the application. And before like front end web development really exploded. This was like something that people commonly did, going on like the website and the back ends and whatnot. And like really when you said backend developer, you probably talked about people who like did more database stuff than just like server-side stuff. And now that role's kind of like morphed into like, okay, we have our backend developers that work on like the APIs and all the backend things and the front end developers which work on the client side. That's because like both of those sides of the equation have gotten a lot more complex over the years. And that's because we're dealing with oftentimes like different programming languages, different platforms, different, sometimes even different operating systems that they use and whatnot. And I was on a team about three years ago before I joined Ionic. And we were kind of in that situation. We had like four or five frontend devs that were working on like an AngularJS Ionic application and one Java dev that was working on the backend. And the front end team was just like really outpacing what the person could keep up with on the backend. And so we got together as a team was like, well, what are some of the things that we could do to solve this problem? And we were kind of like, well, the front-end devs could go and they could learn Java and, you know, get with the tools and stuff to do the Java development. But we also thought like, well, what if we just use like node on the backend to do our development, because everybody on the front end already knows JavaScript. We already had no.

ALYSSA_NICOLL: And the Java developer like hung his head and walks away slowly. 

ELY_LUCAS: No, actually, actually he was pretty cool. He got behind it. Oh, good. Where do you keep them on? I was going to say like, how do we speed up our backend development? Fire the Java developer and we'll do it ourselves. Oh my gosh. But yeah, so that's kind of what we did. And we moved, we moved around to like slowly like writing all of our new stuff in Node with JavaScript. And it was working out pretty good, but we had this microservice architecture. And what we found was that whenever like a developer started up a new microservice, like we didn't have like a whole lot of like guidelines to go by. We were using just like plain express on the backend. And one of the things about express while it's like super easy to get up and running and get rolling with it, express doesn't offer like any type of real guidance on how to architect your applications. 

ALYSSA_NICOLL: So before we go any further, could you, for people who are, have never. Like I've heard of microservices, but I've never used them myself in development. So can you give a quick example of what a couple of microservices were and how you used Express with those? 

ELY_LUCAS: Yeah. And to say like our stuff was like microservices is probably a little bit of a misnomer. Why we tried to break, break it up. It wasn't like super, super microservices, but like we had like an authentication service to deal with authentication. And we had a user service that dealt with the actual users of our application and then different areas around each major functionality piece of our system we had a service for. And so this, like we had a chat service and we had a notification service and a weather service and stuff like that. 

ALYSSA_NICOLL: So each service you're saying there, there weren't very many like rules around how to write them. So it was just kind of chaos between the services. 

ELY_LUCAS: Right. Yeah. And that, that's kind of what we found. And at the time, Angular just popped on the scene and with Angular came TypeScript. And I started really getting into the TypeScript. And I was taking a look at all of our different services and I was like, well, it would be kind of cool if like we could use some mechanisms from TypeScript to help like ease up on the amount of code that we had to write. And I came from a background of like ASP.net development and a little bit of Java Spring development. And so I was kind of like used to like the frameworks providing like these, this type of guidance, how to do things. And one of the things I really liked about ASP.net development is like how you define your routes and stuff. And so I was like, okay, we got in TypeScript, we've got decorators. I would really like to use a decorator to define how my routes are going to work inside of Express application. And then, so I started looking for how to use TypeScript with Express. And that's actually how I found Nest. And so a little bit of background on Nest. So this is about around when Nest was just coming on the scene. I think it was like version 1.0, but Nest was a backend framework that was meant to provide an opinionated way to develop back-end applications. And the way that they accomplished this is that they took a look at like what was going on in the Angular world. And Angular was an opinionated way to develop front-end applications. And so the creators of Nest really got influenced by how Angular was created and tried to reuse a lot of the

ALYSSA_NICOLL: Your pupper is adorable. I love her and she's very welcome on this podcast. 

ELY_LUCAS: She wants to be a part of the conversation. 

ALYSSA_NICOLL: I'm just honestly surprised that you were all for not doing Java, getting on the Node train, getting on the Express train and then discovering Nest when you had a background in ASP.net. And you were ready for more structure and yet you dove into the JavaScript world. So it seems very, 

ELY_LUCAS: yeah, I was the only one on the team that came from a background. Everybody else was, well, most of everybody else was front-end developers. And then the entire company was pretty much JVM Java-based. And it was, it was a little bit of a negotiation with like our CTO and stuff to start using node, but he, he kind of understood the value as well. It's like, okay, you got a bunch of JavaScript developers. We should get them right in JavaScript on the back end as well. But pretty much the entire rest of the company was all JVM-based. 

ALYSSA_NICOLL: And so when you discovered Nest, it was like this breath of fresh air to bring that structure to the backend of this application. 

ELY_LUCAS: Right. Yeah. Because Nest just offered what I like to call building blocks, ways to structure your application that you could use. So, especially if like you were an Angular developer coming to the backend, Nest uses a lot of the same concepts and nomenclature and whatnot that Angular apps do. And so if you see something like a pipe or an interceptor or a guard, it's like, okay, I know as an Angular developer where that logic is going to go. And what I find a little bit funny about it is that, you know, the Angular team were, was a bunch of Java developers originally, I believe. And so when they went to go write Angular, they took a lot of the concepts and stuff that they knew from developing back-end applications into the front end. And so then kind of went like in this big 360. 

BROOKS_FORSYTH: Very cool. I've used Nest before. And I kind of had a similar experience while I started with Firebase and got frustrated with that and then said, I'm just going to write on an express app. And then my express app was spaghetti. And then I found Nest and it made it all pretty again. And yeah, exactly. Made it, made everything work now, but yeah, it's mostly done front-end work for the past like six years. So it was like my first time getting into the backend and it was very easy to jump right into Nest. 

ELY_LUCAS: Yep. And were you an Angular developer before? 

BROOKS_FORSYTH: Yeah. Yeah. 

ELY_LUCAS: Yeah. So that's what I hear. Like Angular developers are able to jump into Nest like super easily just because of how close our architectures are. But I also like to say that like Nest is a platform for building backend applications. And it doesn't matter what your front end is. It doesn't have to be Angular. Like Nest is just as beneficial to like React developers or Vue developers or native mobile developers. Or if you're building like just a system of backends in general, Nest is a great platform for all those things.

ALYSSA_NICOLL: Yeah, potentially a dumb question. So if you're using Angular for sure, and you have a node backend and you want to use Nest, does that mean you are also for sure using Express or not necessarily? 

ELY_LUCAS: So Nest by default encapsulates Express. So it uses Express in the behind the scenes for you as it's HTTP engine. So while a lot of the concepts are similar with Express and you can actually get access to the Express pieces if you need to the development is something about that in the NestJS docs. So I was like, are these linked? Okay. Yeah. But the development experience is like way different from developing an express application and a Nest application. Nest application is more like developing like in another type of MVC framework. And so you have these like clear separations of concerns between like your controllers and your services, your views, which if you're...Right. And like an API, you can probably consider like the view, like the Jason or the model of the Jason that gets returned back to the client. Or if you're using nest to do some type of server-side generated HTML, the HTML would be like your view for the particular aspect. 

BROOKS_FORSYTH: There's also a great like community around it with the plugins and stuff. Have you used any of those or? 

ELY_LUCAS: A little bit. So the backend I typically use to attach to a nest application is like Postgres. And so the the data layer that I use mostly is a type ORM. And if you like everything that Nest is doing, type ORM is architected in a very similar way. There's lots of uses of decorators to define your types and your relationships between entities. And so type ORM, if you're coming from a.NET background, type ORM is like very similar to an ID framework. And so you can use it to...It's a code-first database approach. You can use it to generate your database and run updates to your database as you do like deployments and whatnot. It's pretty cool. Some of the other plugins I haven't gotten too much into, but I know there's like a swagger integration and then you can also use Nest to do stuff that's not just like straight-up HTTP slash rest APIs. Like you could do GraphQL with Nest. You can do web sockets and real-time communication with Nest as well. And so those are some additional plugins out there. 

ALYSSA_NICOLL: Brooks, are there, are, did he encompass the plugins that you've used before? Are there others that you? 

BROOKS_FORSYTH: I mostly want to know if he used the GraphQL one. I haven't used it yet. That's what I was curious. Yeah. Looked at them longingly a couple of times and wanted to have an excuse to start to play with it. Right? 

ELY_LUCAS: Yeah. GraphQL is one of those things that has definitely intrigued me over the past few years, especially since it's gotten more popular, especially in the, in the React world. And when I dive into it, I'm planning on utilizing Nest to to do so. 

CHRIS_FORD: Can I just back up a little bit? When you were saying about how Nest basically encapsulates Express, if you've got a vanilla JavaScript application, you can migrate the TypeScript literally by just renaming your files from.js to.ts and just making sure you compile them. Can you do the same? If I have an existing Express app, can I just load Nest into it and be like, technically now I'm using nest and then I can start building nest bits on top of what I've got. 

ELY_LUCAS: Technically, you probably could because when you go into the main startup file for nest, the main.ts file, what you do is you boot up a version of the application for nest and that application comes from an interface called like, I don't remember the exact name of it, but it's like I nest express application or something like that. And so that application object has the same interface that an express application has. And so if like you were wanting to like hook up like any nest middleware, any existing like, or sorry, not nest middleware, express middleware, it's completely compatible and that's where you do it. And so I would assume that like, if you have existing route handlers and stuff that you wanna use that are express route handlers, you could register them the exact same way there. And then for like anything additional, you just like let the nest portion of the application take control. So it's something I haven't tried, but from what I know, everything about it, it's probably possible. 

ALYSSA_NICOLL: Wondrous since you're so integrated, if anyone from the same team worked on it, or do you guys know who created it? Yeah. 

ELY_LUCAS: So it was created by Camille and I would butcher his last name if I tried to say it, so I'm not going to, but I'm going to include a link down there. And so Camille runs a company called Chillion, I think is what it's called. And so it's kind of, they do a bunch of consulting and education around Nest applications and just kind of application development in general. But yeah, it's, it's an open source project. It's I believe MIT license free, free to use. So you can get started with it, but you know, just kind of a small team, but it's been just exploding in the past couple of years in popularity. I think it's the fastest-growing HTTP library on the node ecosystem for probably a couple of years in a row now. 

CHRIS_FORD: I think it's not monetized in any way. Is it just purely based on like sponsors? And I see they've got like a sponsor us link on, on the website, on the docs. 

ELY_LUCAS: Yeah. 

BROOKS_FORSYTH: They just started selling a course. 

ELY_LUCAS: Yeah. I think that just came today is a Wednesday. I think that just came out a couple of days ago, actually. 

ALYSSA_NICOLL: Oh, wow. Okay. 

BROOKS_FORSYTH: Yeah. Coming from, I converted the app, those previous segment from Express and Nest and it was mostly, I mean, I probably could have still used the Express app and then done Nest things to it. But it was pretty easy just to take my routes and copy and paste and like nest apply them or whatever, put them in the right, you know, type script. 

ELY_LUCAS: Oh, so take like your handlers and put them into controllers and whatnot. 

BROOKS_FORSYTH: Yeah. 

ELY_LUCAS: It's probably, yeah, probably a fairly easy, easy upgrade. 

ALYSSA_NICOLL: So as a completely front end of the front end person asking this question, front end of the front end. 

ELY_LUCAS: Yeah. Like what's the front end of the front end? Literally. You're just, you're just the one using it. You're actually using monitors. 

ALYSSA_NICOLL: Like when I say I'm a front end web dev, I mean it. I don't touch the nodes. That's what I mean. Like I'm like, Hey, I can totally make like, for instance, in my last job, I was tasked with building a gradient color picker from scratch, like, and matching. Oh, it was awesome. It was well, and then matching those colors and making them as true to form with the print colors, cause I worked for a print company and so I freaking had a blast. I love building custom components. And CSS is my jam and that's where I live. So whenever I talk about things like this, it's a little intimidating. And so Brooks, you're talking about, okay, I'm converting this express app to nestify it. Do you find it's a bunch, did you or Eli find it was a bunch of overhead to like X all this extra syntax, all these extra files, all of this X. Like, yes, it's more structured, but in my mind, it's also like all this extra stuff you have to do to get the same functionality. So can you talk about to that for a sec? 

BROOKS_FORSYTH: No, I like that because I had lived through my spaghetti code for about a month ahead of time. Right. So I had banged my head against the keyboard enough where my head still hurt. So it was a relief to have all this structure. I don't know you live. 

ELY_LUCAS: Yeah. And, and for me, like, probably like really depends on the situation, but like most of the time, like I'll give you a situation I just popped up a couple days ago where I was going to go write a Lambda function on AWS and I wanted to like prototype it and stuff locally before I actually started to put it, put it into Lambda. And I happily started up a nest application and started to prototype it up, up there. And then my, what I ended up doing was basically once I got done, it was a super simple method to like switch out like headers on HTTP requests and stuff like that. And so once I got it done, like I just took the, took JavaScript out of the nest application and copied it into AWS's, Lambda's editor and got it up and running there. But what I why I did that as opposed to like trying to fire up a express application is that the nest CLI makes it so easy to like fire up a new app and to get stuff like debugging and you know, to run a server. 

ALYSSA_NICOLL: The angular CLI for granite. So you're saying to do that stuff and express it's by hand. There's no express CLI. 

ELY_LUCAS: I imagine somebody's probably written one out there. I'm not aware. I'm not aware of any. And I don't think there's any like de facto standard that people flock to for generating express apps. But yeah, the Nest CLI is very similar to the Angular CLI. I think it's based off the same code base and they use like Angular schematics and whatnot so that you can easily generate like new controllers and modules and all the different various pieces that you can for a Nest application. But yeah, it was just so easy to get them running. Like I was like, I'm not even going to try to like fire up a Nest application and whatnot on my own. Like I could have, but it would have just taken longer.

ALYSSA_NICOLL: Okay. So because of the CLI and also your love and need for structure, it's not a hassle or it's not tedious to do things in Nest. 

ELY_LUCAS: Right. I think the CLIs are great for that because I do the same thing. If I want to just test something out in an Angular thing, I know I should technically go to like stack blitz, but if I'm not going to stack blitz, I love the fact that I can just drop a fresh Angular application, you know, on my desktop with the CLI, just with a simple command. You know, and all 10 million node modules that comes with it. I have so many test apps. 

ALYSSA_NICOLL: I actually recently just went through and cleaned it up. It was very cathartic. I recommend it. 

ELY_LUCAS: I was going to say I changed jobs when my dev folder gets too full of test apps, you know, sorry, I have to resign. There's too much here. I don't know what's important anymore. Take my laptop. 

ALYSSA_NICOLL: There's nothing I can do.

CHRIS_FORD: I'm interested in about the, what you were saying about the serverless stuff. Like is there any, do any of the serverless function places have support for Nest? Cause I know that you can like, right. I mean, I don't do serverless stuff. I'll be honest. There's something I've been interested in, but I've never been brave enough. I know like with Microsoft, I never know how to pronounce this Azure, right? Yes. Over here. That's that word is pronounced Azure. So I never know what to call it. So with the Azure functions. I'm fairly confident in saying that you can, you can write them in node, right? So is there nest support for that? If you want it to. 

ELY_LUCAS: Yes, there is. And I am quickly, almost as if I'd planned that question. I didn't. There is a project out there. I want to find the name of it so I can actually talk about it here. 

ALYSSA_NICOLL: I feel so bad, Chris, because I have a heated blanket on my lap right now. 

CHRIS_FORD: You can see how I'm just dying here. 

ALYSSA_NICOLL: Yeah. Sorry, darling.

CHRIS_FORD: I've actually, I have actually opened my window now. Tell me if the traffic noise gets too bad. 

ALYSSA_NICOLL: I haven't heard actually anything. So open them all. 

CHRIS_FORD: Well, I've only got two. Don't go very far either. 

ALYSSA_NICOLL: So we were asking if there's a way to use Azure with Nest in. 

ELY_LUCAS: Yeah. And probably like serverless in general. So I know, I know there was a team of the Azure dev advocates out there probably six to nine months ago put together a small project to make it super simple on pushing Nest applications up to Azure functions. And I know there's a similar project that you can use to do it to either, with AWS Lambda as well. And I played, I have played around with the Lambda one before, and I wanted you to get into the Azure one and check it out. 

ALYSSA_NICOLL: Yeah. I'm looking at this post right now. It's Nest ad Nest JS slash Azure function HTTP. 

ELY_LUCAS: Yeah. 

ALYSSA_NICOLL: So it looks like, yeah.

Time is of the essence when it comes to identifying and resolving issues in your software, and our friends at RayGun are here to help. With RayGun alerting, get customized error, crash and performance alert notifications sent directly to your preferred channel with integrations including Microsoft Teams and Slack. Set thresholds on your alert based on an increase in error count, a spike in load time, or new issues introduced in the latest deployment along with custom filters that give you even greater control. Assign multiple users to notify the right team members with alerts linked directly to the issue in Raygun, taking you to the root cause faster. Never miss a runaway error. Make sure you're quickly notified of the errors, crashes, and front-end performance issues that matter the most to you and your team. Try Raygun alerting today and create a world-class issue resolution workflow that gives you and your customers peace of mind. Visit raygun.com to learn more and start your 14-day free trial today. That's raygun.com.

ELY_LUCAS: Yeah. And so basically what it's kind of like a little piece of middleware library that will, because generally functions are agnostic to what type of trigger triggers them, if it's like an HTTP trigger or something like that. And so what the libraries do is they listen for their trigger requests to come in and then see if it's an HTTP trigger, they kind of reconstitute all the objects, the request objects and the context and all that kind of stuff. And so when it actually gets to your Nest application. It feels like it actually came in from my HTTP request instead of a trigger. And so like it can do it's routing with the URL and get access to the headers and all that fun stuff. I thought I had a cool name, but I'm looking at the blog posts now and it kind of looks like it's just called Azure. 

CHRIS_FORD: We can make one up. 

ELY_LUCAS: Yeah. Let's name it now and then submit a full request. Nest Azure Coolness. Nassir. Oh, I'm a Nassir developer.

Yeah. Super specialized. Yeah. So what's your experience? I've written a load of Azure functions in Nest. 

ALYSSA_NICOLL: In Nest? 

ELY_LUCAS: Specifically. Yeah. So sometimes it might be a little bit of overkill to do something like a serverless function in Nest. But if you're planning on, you know, probably taking a little bit too much of an advantage of a serverless platform and trying to put like a whole application into a serverless function, like something like Nest will probably make a bit more sense. 

CHRIS_FORD: Pretty sure there's people out there who would tell you that is exactly how you should be building your, your backends of your applications. Right? 

ELY_LUCAS: Yeah. I mean, I don't, I don't think that's what it was meant for, but when you think about like the terms of scalability and low cost and whatnot that a serverless infrastructure gives you, it makes a lot of sense to do so. All right. And so with that, maybe you can talk a little bit about like some of the things that Nest does when I talk about like the guidance that it gives you, I want to do and, and how like it's influenced by Angular. 

ALYSSA_NICOLL: Yeah. The building blocks, as you call it. 

ELY_LUCAS: Yes, the building blocks. And so it kind of starts off with modules and as Angular devs, you're pretty familiar with modules and the Nest application modules look very similar. And they kind of provide the same concept and capability that modules do in the Angular world and being able to break down your application into smaller pieces. And then combine them back together into a larger application. Now I'll kind of be honest, like in my nest work, like I don't think I've ever like actually separated out a module and if the CLI didn't do it for me in Angular, I probably would say like I've done it in Angular either. 

CHRIS_FORD: So offensive, modularize all the things. 

ELY_LUCAS: Yeah. 

CHRIS_FORD: Well, the module per file, that's me. 

ELY_LUCAS: Yeah. Well, the CLI does it for me now, so I don't have to worry about. making sense anymore. 

ALYSSA_NICOLL: Right. Though I do feel very at home looking at these docs. Cause like, for instance, you're talking about modules and it says import module from nest JS slash common. And it's very, it's a very angular esque. All of that. 

CHRIS_FORD: It looks just like angular, doesn't it? Like literally the, the only thing that lets me know I'm not looking at angular code in the docs here is that it's just at module and not at ng module is literally the only difference. 

ELY_LUCAS: Right. And so then with that, you also have your services and providers. And so in a typical backend MVC style architecture, your services and providers are kind of what's responsible for like communicating with the database, some type of third-party storage system, other APIs, other backend services and whatnot. And so that's their responsibility. And then you have controllers and we don't have controllers in Angular anymore, but we did in Angular JS because when Angular JS first launched, they called it like the MVV star framer or something like that, but it was kind of like, like I eluded to earlier that Angular JS was kind of modeled after backend development. So it was kind of like a MVC framework, but on the front end and controllers and an MVC application are what's responsible for communicating with your client and relaying those messages back to your services and then responding to the client with the output services. And so got the controllers that do that and the controllers and a web API are what listened to the HTTP requests coming in. And so a controller in Nest is pretty simple to set up. It's just the basic ES6 class that has a controller attribute attached to it. And the controller attribute takes in a string, which defines the route that it's going to listen for. And so let's say you have like a people API. And so the controller attribute would take in forward slash people. And that lets Nest know that this controller is going to listen to all those requests that come into forward slash people. And inside of the controller, you're going to have methods. And if you want to have your controller listen to a particular HTTP verb that comes in, you would decorate that method with that particular attribute. And so you have like a get attribute to respond to get requests and a put attribute to respond to put requests and post and delete and so on and so on. And so you put those attributes on those individual methods. And so if you have like a, a get list or a get people to return back a list of people, you put a good attribute on that. And then if you have like another get request, that's only going to return back in individual inside of that, get it. I keep, I keep calling them attributes, but I also mean like decorators because I come from a dot net world originally, but you have the get decorator and you can specify dynamic parameters inside of that get decorator as well. And so you can specify an ID. So if somebody goes to forward slash people slash one, the get decorator that has the dynamic parameter attached to it knows that this is the method that's going to respond to that, to return back a individual person. 

ALYSSA_NICOLL: So can we back up a step and look at what we just, so we've covered modules and controllers so far and basically you have this module which is going to point the way at like in their docs, they have like cat's controller and cat's service. So it's like pointing out both of these pieces. So for every, is it true to say like for every controller that I need, I have a module? Is that the..

ELY_LUCAS: Only one module. Yeah, that's not what. 

ALYSSA_NICOLL: So you could put them all in one module and just like keep. 

ELY_LUCAS: Yep. You could put them on all in one module and by default, I believe that's what the Nest CLI does for you. So if you use it, the Nest CLI to generate a controller, it's going to update the app module and unless it, unless it's a little bit more smarter. And if like you have a module already in that folder or something, it might update that module, but by default, it's going to update the main app module. 

CHRIS_FORD: I was going to say like with, with the Angular CLI. It actually just looks for the nearest module, doesn't it? To where you're putting it. 

ALYSSA_NICOLL: Does it? Shut up. 

CHRIS_FORD: Yeah. So if you have like, if you have two modules in the same folder, like if you have like your material module and your app module, obviously it's a good place to put them, if you do just like nggc, my new component, it will actually flag up and say, you need to specify which module you want to put it in because there's two in the, the two are the closest ones. But so if you then had a like a subfolder like, you know, cheese and you had a cheese module in there. Yeah. Yeah, I'm going with this. Like, if you had the cheese module there and then you do like nggc cheese slash and crackers component, then it will import your crackers component into your cheese module because it's the nearest local module to the component.

ALYSSA_NICOLL: So what Eli was saying is by default, when you just, I'm going to, I'm going to use nest today and you use it in, it's going to use your app module. It's not going to create its own module.ts file for all the bits to be configured in. 

ELY_LUCAS: Correct. 

ALYSSA_NICOLL: Okay. And then controllers, as you were saying, there were, sounds like all of your methods for like, you know, get and find all, and all these things are defined. But then I feel like we're missing, are we missing a piece? I feel like we're missing a piece. 

ELY_LUCAS: Yep. And so inside of our controller, if we're calling, if we want to return back a list of people, like where do we get that data? Right. And so that's where the services and providers slash providers come in. And so just like in Angular, we inject our services via the constructor into our controller. And now we have access to that service and all that wiring up of the dependency injection system is done in the module very similar to how it's done in Angular. You have your provider section, and you just list it in the provider section. That way, it knows about it. 

ALYSSA_NICOLL: Really don't like it. I feel like the word provider and service are interchangeable. Is that true? 

ELY_LUCAS: Yeah, I would say all services are providers, and providers can be other things as well. 

ALYSSA_NICOLL: Dang it. 

CHRIS_FORD: Yeah, if you think about it, and this is not me talking from actually knowing, this is my assumption. In your Angular app, your services go in your provider's array in your module that you have to provide your service. So, 

BROOKS_FORSYTH: Oh, I thought you just put them in one of those arrays until it worked. 

ALYSSA_NICOLL: Yeah. I know you're probably being facetious, but like, well, 

BROOKS_FORSYTH: that's how you start. 

ALYSSA_NICOLL: At least some people really do that. 

CHRIS_FORD: But my services are all in my entry components. Why is it not working? 

ELY_LUCAS: And so one of the cool things that nest does that you would normally have to wire up yourself in an express application is that. In order to get like an HTTP request that returns back like a bit of JSON and express application, there's various pieces of like middleware and stuff that you have to like hook up. Like you have to like hook up like a, I think it's a middleware called body parser, like if you're taking in like a piece of JSON requests and stuff like that. Nest handles all that stuff for you. And so if you're doing a, like a post request and your body has a bit of JSON and the content type is application slash JSON. Nest is automatically going to take that JSON and inject it into a parameter in one of your controller methods. And so if like you're accepting a person and a post request, all you need inside of your controller is like a create person method that takes in a person object and Nest will automatically map that JSON response into that person object for you. 

BROOKS_FORSYTH: That's awesome. 

ALYSSA_NICOLL: Yeah. So like no need to do, no need to start yourself off with learning express is what you're, you're saying. Just go straight to Nest.

ELY_LUCAS: Like never, never learn Express is I think the key. 

ALYSSA_NICOLL: It sounds like it. I I'm really, I know we're, we're almost to the top of the hour. We've got probably 10 more minutes to dive into anymore of the building blocks. But I feel like I've got a really good handle on at least the basics are, are there any other like this one? Like, 

ELY_LUCAS: yeah, yeah. So there's other pieces of, so now we're, we're getting into specialized pieces of middleware and in an express application, middleware can sits in between the client the back end of the system, the response, and you can do various things. Nest has middleware as well, but they're very specialized in what you do. And as Angular developers, when you hear the names of these, you're going to be kind of familiar with what they do. And so we have pipes and so pipes and Nest serve kind of the same purpose. They're often used to convert various pieces of data as they're coming into your system into a particular format. Where like a pipe and Angular is used to like convert something for display purposes. And so pipes are often used to convert data. So like if you have a string, but do you want it to be a number or something like that, or a particular object that needs to be morphed a little bit before it actually hits your controller. You can also use pipes for validation. And so pipe is a good place for you to be able to look at the request coming in and validate the input before you actually send it to your controller. And then you have interceptors and interceptors listen to both ends of the request, and so it can listen to the beginning of it take a look at the data and then pass it through the rest of the pipeline, let it go through your controller, and then it gets access to the data again at the end where you're now free to modify that data as it goes out. And so like what you can do there is like, if you have a specific schema that you like your responses to adhere to, like now's your time to like put the data into a data field and the metadata into a metadata field and whatnot. And then you also have guards. And guards are very similar to Angular guards. They're kind of like provide authentication for your app. And so a guard can intercept a request, this is coming in and you can do all your authentication checks on it to make sure that the user is allowed to access this resource and pretty much like return true to them through or return false to give them a forbidden request status code back. But what I like about these is kind of the express world, all the only building block that you have is a piece of middleware and you kind of have to figure out how it's going to fit into it all, where these are like very specialized. And so like, when you think like, okay, I'm doing authentication. I know to put that into a guard, or if you're a, a developer who knows Nest, but you're going to another Nest application, you kind of know that like, okay, if I'm going to look at authentication code, I'm going to the authentication guard for that versus like, you know, having to ask somebody like, Hey, where's the authentication code for, for the app in this and whatnot. It's just that, uh, you know, pretty opinionated guidance that I enterprise grade framework like nest gives you that something like express doesn't. 

ALYSSA_NICOLL: I, you have 100% sold me on nest JS today. So to back up just real quick, I saw that when you're talking about pipes, there is like six different built-in pipes with nest, like validation pipe, parsant pipe, do you know if there's a way to build custom pipes? 

ELY_LUCAS: Yep. Yeah. So all these you're, you're able to build custom versions of them and the built-in ones are like scenarios that the Nest team knew were going to happen so often. They just included them out of the box, especially like validation and then like the parse int pipes, because it's very common for you to take in like a parameter from a dynamic parameter from like a URL and inject it into your controller. But anything that comes from the URL is going to be a string where a lot of the times if you're using integers or numbers for your IDs, that's going to come in as a string and you'd normally have to convert that yourself into a number before you pass it into your backend parse it and pipe just automatically says like when you decorate a parameter in your controller method with parse and it's going to be like, okay, if it's going to be a string come again, automatically convert it to an integer. And then when it arrives into your controller, it's going to be an integer. 

CHRIS_FORD: What, what happens out of interest if you try to navigate to like slash cats slash B like what would your passing pipe do if you actually passed it a letter, would it just like four or four or

ELY_LUCAS: It would probably give you, I think it would be a 400 bad request exception to let you know that you probably did something I'm not exactly sure. That's what would happen, but that's what I would, I would want it to happen. 

BROOKS_FORSYTH: There's always one, isn't there? Try to think of these scenarios. 

ELY_LUCAS: Cause the bad request is to say like, Hey, you as a caller at the API did something wrong, 

BROOKS_FORSYTH: true blame the user. 

ELY_LUCAS: Yeah, exactly. 

BROOKS_FORSYTH: I agree always. In fact, it's all I ever do.

ALYSSA_NICOLL: Well, actually, is this exactly what the docs say? Cause it says that it would throw, nest will throw an exception like this. Validation failed numeric string as expected. Status code 400. Yeah. 

CHRIS_FORD: We've definitely established out of the two of us, who knows their status codes. 

ALYSSA_NICOLL: Oh my goodness. So yeah, I am very impressed. Honestly, you lied. I don't know like how you know so much. I feel like you have a secret in with the nest team. Cause. Your, your knowledge is very, 

ELY_LUCAS: you know, honestly, it all comes from the docs. Their docs are amazing and you can go through and read those and whatnot. But besides that, like I've, I've just been a huge fan of nest ever since it's a released and I've done, you know, toxic user groups about it and whatnot. And I'm putting together a course for it. 

ALYSSA_NICOLL: Nice. 

ELY_LUCAS: Yeah. I talked to Angie conf once on it. 

ALYSSA_NICOLL: So is that, do you think your course will be ready when this episode drops? 

ELY_LUCAS: I hope so. I've been working on it for quite a while now. 

ALYSSA_NICOLL: Where can people find it? What platform is it on? 

ELY_LUCAS: It's going to be on a Thinkster. So yeah, I've been working on that for a while. So hopefully by the time this podcast airs, that it will be up and ready to go. And if you're interested in learning some Nest, go over to Thinkster. And also I'd like to promote the Nest team's official course as well, because the more learning there is out there, the better it is for the community. 

ALYSSA_NICOLL: Awesome. That's wonderful. So yeah, check out Eli Lucas's Thinkster course. I think it's thinkster.io on Nest JS. And before we get to any more of Eli's picks or actually picks in general, is there anything else about Nest or Express or anything else you want to add on before we get to picks? 

ELY_LUCAS: Nope, nothing at the top of my mind. Just like it's, it's a framework. And what I would say is like, it's, it kind of brings back some of the joy of like, you know, developing back in applications again that kind of missed for a while, especially coming from the ASP.net MVC world. And so it's like your, if you're used to like enterprise type systems that you'd find in other frameworks, give it a try. If you're an Angular developer, give it a try. If you're not an Angular developer, it's still a great platform for building back-end applications on Node. So give it a try as well. 

Hey, this is Charles Maxwood. I just wanted to talk really briefly about the top end devs membership and let you know what we've got coming up this month. So in February, we have a whole bunch of workshops that we're providing to members. You can go sign up at topendevs.com slash sign up. If you do, you're going to get access to our book club. We're reading Docker deep dive, and we're going to be going into Docker and how to use it and things like that. We also have workshops on the following topics, and I'm just going to dive in and talk about what they are real quick. First, it's how to negotiate a raise. I've talked to a lot of people that they're not necessarily keen on leaving their job, but at the same time, They also want to make more money. And so we're going to talk about the different ways that you can approach talking to your boss or HR or whoever about getting that raise that you want and having it support the lifestyle you want. That one's going to be on February 7th, February 9th. We're going to have a career freedom mastermind. Basically you show up, you talk about what's holding you back, what you dream about doing in your career, all of that kind of stuff. And then we're going to actually brainstorm together, you and whoever else is there and I, all of us are going to brainstorm on how you can get ahead. The next week on the 14th, we're going to talk about how to grow from junior developer to senior developer, the kinds of things you need to be doing, how to do them, that kind of a thing. On the 16th, we're going to do a Visual Studio or VS Code tips and tricks. On the 21st, we're going to talk about how to build a software course. And on the 23rd, we're going to talk about how to go freelance. And then finally, on February 28th, we're going to talk about how to set up a YouTube channel. So those are the meetups that we're going to have along with the book club. And I hope to see you there. That's going to be at topendevice.com slash sign-up.

ALYSSA_NICOLL: All right. Well, panelists, Brooks or Chris, do either one of you have some picks to go over today? 

CHRIS_FORD: I have one pick. It's unlike me. I actually have a whole bunch of them, but I'm only going to pick one thing because I'm too hot. I need to move out of this room. I'm going to pick a TV show called What We Do in the Shadows. Just finished watching the second season of it. I think it's made in joint collaboration between BBC and FX. So in the UK it's on BBC, I've no concept of how you would possibly watch it in the States, but it's like a mockumentary kind of in the vein of The Office, where you've got a TV crew following. But it's following these four vampires who live together in Staten Island. And they're completely inept. One of them isn't even a proper vampire. He's just like, he's what he calls an energy vampire, which basically just means he just bores people and then like feeds off of their life force and so they just are passing out from sheer boredom. It's absolutely hilarious. Um, it's very, very wittily written. And I would, 

ALYSSA_NICOLL: you can watch it FX on Hulu is what this is saying in the States. 

CHRIS_FORD: So excellent. I mean, I would, I would, if you like witty comedy, I would absolutely recommend it is very, very, I feel like, 

ALYSSA_NICOLL: I feel like Chris, you're like, you know, if you're at all a cool person, like, watch it, like it's, 

CHRIS_FORD: it's, it's, it's so well written. I can't even, I mean, the concept of it is, is insane, but it's very well done. And I would recommend it.

ALYSSA_NICOLL: Yes, darling. 

BROOKS_FORSYTH: Okay. Yeah, I go second. It's the rule. Yeah. So my pick is a neural cam and it turns your smartphone into a webcam. And I was playing with it before. I was going to use it on this, but it didn't, it didn't happen. I'll put it in the chat and yeah, you know, it makes you look better in general. And also if you pick your nose while it's on, it'll blur your face out. So that's good if you're into picking your nose. I think it also...Blurs out nudity as well. So if you accidentally get naked, it'll blur you out. 

CHRIS_FORD: Does that accidentally happen to you a lot? Right on the zoom calls? 

BROOKS_FORSYTH: All the time. Everything here is just Velcro down the side. That's right. Sometimes it gets snagged on my chair or something and I like get up to go, you know, close the door and I'm just butt naked. 

ALYSSA_NICOLL: I'm imagining you in like one of those track suits that you just like rip off at the Velcro. Yep. 

BROOKS_FORSYTH: Exactly. 

ALYSSA_NICOLL: Neural cam. Okay. Very cool. 

BROOKS_FORSYTH: Yeah. It was cool. I was playing with it. I've played around with a epoch cam, which is kind of, kind of similar, except it doesn't have some of those cool blurring effect features, but I had the same problem with zoom, like it didn't work with zoom, but like I could use it in other applications, it was kind of weird. 

ALYSSA_NICOLL: My pick is super quick. It is on Twitch, code it live. I stream there very often with my cohorts, but every Wednesday afternoon from two to four, I do a UI show where we tackle complex CSS problems. So yeah. Come join me at that's two to four central. I'm really bad at converting, so I'm not even going to try. So there you go. But Eli, other than your Thinkster course, which everyone should go check out. Do you have any picks for us? 

ELY_LUCAS: Um, yeah, I'll pick a TV show too. And it's not exactly new, but I'm just starting to get into it. And which is kind of late for me because I've been a tricky all my life. I recently started watching Star Trek discovery after I watched a Star Trek, but card and I'm really enjoying it. It's, it's kind of hard to call it Star Trek because it's so different. But yeah, it's, it's really good. It's a little bit, a little bit darker and more mature than Star Trek that you might be used to, but yeah, liking it. And next thing I like to throw out there is at Ionic. We just recently got done doing our Ionic Conf, which was a virtual conference celebrating web development and technology and hybrid mobile development and all that fun stuff. And we just put up all of our sessions on YouTube. And so if you go to youtube.com slash Ionic framework, you can view all of our sessions for IonicConf. 

BROOKS_FORSYTH: I actually, I watched some of it live. I watched the web VR one. Yeah. 

ALYSSA_NICOLL: Well, Eli, thank you so much for coming on the show and teaching us all about the wonders of Nest and you're a wonderful, wonderful guest to have on. So seriously, thank you for taking time to join us. 

ELY_LUCAS: Yes. Thank you. Have a great time. 

ALYSSA_NICOLL: Well, that is a wrap. We'll see you next time.

 

Album Art
Amazing Backends for Angular Devs with NestJS with Ely Lucas - AiA 400
0:00
42:51
Playback Speed: