Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angular NestJS

Angular NestJS

All-the-way: Angular ❤️ NestJS

You love Angular, TypeScript, and you are fluent in building client apps? At some point, you may need to write server-side APIs. As it is natural to use the same language in the backend as in the frontend, you are likely to choose Node.js. However, when using libraries like Express or even plain Node you are often leaving known territory lacking good idioms and structural patterns.

Have you ever heard of NestJS? It is a framework to build efficient, reliable and scalable server-side applications. What is remarkable about it is that it uses similar concepts as Angular. You can organize your code into modules. It works with dependency injection of services into controllers (which are in a way your components for API routes) and even has a CLI to get you started quickly.

We will investigate what a project structure with an Angular front- and NestJS backend could look like, we proceed to implement our first API routes and we finally conclude testing them. Since it is so easy, we will also generate a nice API documentation on-the-go and will take a peek at helpful, already built-in plugins. In the end, you should be ready to develop your full stack web application using a marriage of Angular and NestJS.

David Würfel

October 15, 2019
Tweet

More Decks by David Würfel

Other Decks in Programming

Transcript

  1. h DATA VISUALS v LOGIK q USER RESEARCH w INSPECTION

    e TESTING t NAVIGATION z INTERAKTION r MODELLING a GAMIFICATION s VISIONt1 d SCREENS f ICONS g ANIMATION j 3D k ASSETS l PROTOTYPING ö FLOWS ä STYLEGUIDES y LOOK & FEELS x MARKUP c ARCHITEKTUR AgAHDAoDBAA
  2. „Hey! My name is Andre Gular. I am looking for

    a companion. Someone who is similar to me and for whom my hobbies are fine.“
  3. http://localhost:3000/companions [ { "id":"express", "name":"Eliza Xopress", "markdownName":"*E*liza *X*o*press*", "avatar":"robotrabbit" },

    { "id":"vanilla-node", "name":"Vanilla Nodesto", "markdownName":"*Vanilla Node*sto", "avatar":"deer" }, { "id":"adonisjs", "name":"Adones Johnson", "markdownName":"*Adonis J*ohn*s*on", "avatar":"otter"
  4. ▪ ▪ ▪ tsc init ts-node ▪ ▪ ▪ ▪

    .gitignore ▪ ▪ > npm install express --save > npm install @types/express --save-dev
  5. „I said hello to Eliza Xopress. We met a couple

    of times, but I think I can‘t handle her. She is kinda messy and has little structure in her life.“
  6. „I‘ve met with Andre Gular. I've done my best to

    make us understand each other. However he couldn't handle my loose lifestyle.“
  7. „I think I need to start over. I will update

    my profile details again. I need to find a good match.“
  8. ▪ ▪ ▪ > npm install –g @nestjs/cli > nest

    new <project-name> > cd <project-name> > nest start --watch http://localhost:3000 Hello World!
  9. http://localhost:3000/companions [ { "id":"express", "name":"Eliza Xopress", "markdownName":"*E*liza *X*o*press*", "avatar":"robotrabbit" },

    { "id":"vanilla-node", "name":"Vanilla Nodesto", "markdownName":"*Vanilla Node*sto", "avatar":"deer" }, { "id":"adonisjs", "name":"Adones Johnson", "markdownName":"*Adonis J*ohn*s*on", "avatar":"otter" http://localhost:3000/companions/express { "id":"express", "name":"Eliza Xopress", "markdownName":"*E*liza *X*o*press*", "avatar":"robotrabbit", "characteristics":[ "quite a fast runner", "little structure in life", "somewhat popular", "a tad messy" ], "favoriteColor":"#88E1F8" } > curl -d ‘{ “myId”: …, “contactId”: … }’ http://localhost:3000/contact http://localhost:3000/companions/:id
  10. GET

  11. „I‘ve met with Andre Gular. He is a really nice

    guy. Our interests coincide to a large extent.“
  12. „Meeting Nesta Jason was a real breeze. We have so

    much in common. However we still have some things to clear up.“
  13. „We‘re talking on the same wavelength. Seems to good to

    be true. I am still unsure whether Nesta is herself and doesn‘t pretend to be someone else.“
  14. ▪ ▪ ▪ @nestjs/TypeORM ▪ @nestjs/mongoose ▪ ▪ > npm

    install --save @nestjs/mongoose mongoose
  15. „Nesta is awesome and a true match! I am so

    happy, I would even go so far to secure our friendship through some kind of contract.“
  16. „I am sure that we can deal well with our

    mistakes and that our friendship will last for a long time.“
  17. „I want to thank Nesta for being such a good

    friend with something special.“
  18. ▪ ▪ SwaggerModule ▪ ▪ > npm install --save @nestjs/swagger

    swagger-ui-express http://localhost:3000/api
  19. GET

  20. „Andre, that wouldn't have been necessary. You are so attentive,

    making my wishes come through. Thank you so much!“