<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tobias Laber on Medium]]></title>
        <description><![CDATA[Stories by Tobias Laber on Medium]]></description>
        <link>https://medium.com/@tobeno?source=rss-b8904146217f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DchjmzA8PaqkLGAV.jpg</url>
            <title>Stories by Tobias Laber on Medium</title>
            <link>https://medium.com/@tobeno?source=rss-b8904146217f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:25:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tobeno/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started with NestJS]]></title>
            <link>https://medium.com/limehome-engineering/getting-started-nestjs-32faa82f3d4b?source=rss-b8904146217f------2</link>
            <guid isPermaLink="false">https://medium.com/p/32faa82f3d4b</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[limehome]]></category>
            <dc:creator><![CDATA[Tobias Laber]]></dc:creator>
            <pubDate>Thu, 14 May 2020 11:00:09 GMT</pubDate>
            <atom:updated>2020-06-14T15:24:03.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IRsZa9BuoCIslj82XNrP-Q.jpeg" /></figure><p>Tobias Laber | Senior Software Engineer</p><p>So we picked NestJS and Serverless. Why? Check <a href="https://medium.com/limehome-engineering/a-nestjs-microservice-with-serverless-framework-3435fac7e0bd">this great article</a> written by my colleague Matthias.</p><p>We took on the challenge of building a REST API from scratch using NestJS on AWS Lambda with Serverless, Docker and TypeORM. By doing so, we are now closing in on our release and the API is still growing fast. But how did we get there? What did we learn on the way?</p><p>We wanted to look back and invite you to our fast-forward version through the journey we took. Furthermore, we really wanted to save you from making some of the mistakes we did.</p><h3>First steps</h3><p>Since both of us never worked with NestJS for a larger project before, we started where most projects are born. A getting-started-page on the project to guide us on our <a href="https://docs.nestjs.com/first-steps">First steps</a>. (<a href="https://docs.nestjs.com/">NestJS docs</a> are amazing btw, huge thanks to the community there! 👍)</p><p>So, two commands later, we had our app (you need NodeJS installed):</p><pre>$ npm i -g @nestjs/cli<br>$ nest new nestjs-starter</pre><p>This gives you a basic setup with some tools out of the box which you can always tune later. NestJS does not force much on you, it just guides you instead.</p><p>Some design decisions in the setup felt weird in the beginning, but we decided to go with them and stick to what the framework suggests. We never looked back.</p><p>Especially when you start off:</p><blockquote>Tip #1: Go with the flow and take the path laid out in front of you. Get a feeling for what the creators had in mind. They use established libraries together with proven patterns. So nothing wrong with following that road for a bit.</blockquote><p>This makes it way easier to use ready to use guides and also the <a href="https://docs.nestjs.com/cli/usages#nest-generate">generator tools</a> that NestJS offers:</p><pre>$ nest generate controller controllers/user</pre><p>Oh, we decided to organise by type. But more about that later.</p><h3>Keeping things clean</h3><p>Before we start getting deeper into the coding business, we wanted to get some standard stuff out of the way. Fast-growing projects get messy at the beginning rather than later in the project. It was, therefore, time to add some tools to support us with that.</p><p>NestJS already comes with <a href="https://prettier.io/">Prettier</a>, <a href="https://eslint.org/">Eslint</a> and <a href="https://jestjs.io/">Jest</a> out of the box. A little mainstream, but they are solid choices. We also threw <a href="https://github.com/okonet/lint-staged">lint-staged</a>, <a href="https://github.com/typicode/husky">husky</a>, some proven Eslint plugins and some config into the mix:</p><pre>npm i -D lint-staged husky eslint-config-airbnb-typescript eslint-plugin-import eslint-plugin-jest eslint-plugin-local</pre><p><a href="https://github.com/taskworld/eslint-plugin-local">eslint-plugin-local</a> is a super simple but still amazing helper to easily write local rules without relying on local NPM packages. It is not perfect and not reusable, however, still a great choice if you want to keep things simple for your team. 😄</p><p><a href="https://github.com/typicode/husky">husky</a> and <a href="https://github.com/okonet/lint-staged">lint-staged</a> make sure you don’t commit nasty things by accident.</p><blockquote>Tip #2: Take care about quality early on. NestJS get’s big, fast. To not waste time with refactorings early on, automate what you can. NestJS is perfect for that.</blockquote><p>I’ll repeat it once more, because of the seriousness in the issue; Establish patterns and quality early on in the project. Otherwise, you WILL hate yourself. NestJS only works if you want to invest in it. Furthermore, NestJS does it’s best to help you. Once you get used to it, you’ll become extremely fast without sacrificing quality. One of the things I really love about the framework. 😍</p><h3>Time for a test run</h3><p>Time to get it up and running for a first systems-check. We decided to go with a standard docker setup for dev. We also added a Postgres DB that we will use later. If you don’t have docker yet -&gt; <a href="https://docs.docker.com/get-docker/">https://docs.docker.com/get-docker/</a></p><p>And now it’s time to say hello to the little one:</p><pre>npm run docker:up</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwRIR8hn1YH3CRX5neNW7Q.png" /></figure><h3>Getting things organised</h3><p>So, time put things into places. We went with a content-type based structure to keep things clean. Often we split by feature, but if you throw <a href="https://docs.nestjs.com/modules">NestJS modules</a> into the mix, you get the best of both worlds. Brain-dead namings for most of the things while still keeping logically connected things together.</p><p>NestJS does work with any structure, just pick what works best for you. It is really simple to move stuff around if needed.</p><p>Here we also ensured we stick to something that works well with the generators:</p><pre>$ nest generate module modules/demo<br>$ nest generate controller modules/demo/controllers/hello<br>$ nest generate service modules/demo/services/hello</pre><p>Check the NestJS docs for more details on <a href="https://docs.nestjs.com/controllers">controllers</a>, <a href="https://docs.nestjs.com/providers">services</a> and <a href="https://docs.nestjs.com/modules">modules</a>.</p><p>These already cover the absolute core of NestJS: It’s dependency management with injection and modules. Ensures you get the nice stuff from Angular without all the heavy baggage that it also brings.</p><p>So, now we are ready for some growth:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*UmwJDKf4XoO1EL4z_DRGoA.png" /></figure><blockquote>Tip #3: Use a structure that works well with generators and relies heavily on fixed patterns. Stupid but automated beats perfect names. This is what gives you the speed you need to stay focused on the important things.</blockquote><h3>Who needs tests?</h3><p>NestJS may bring quite some boilerplate and some people might disagree with the default organisation, BUT: The patterns it establishes, make tests super easy. Seriously: Tests were always a huge pain and we always lost test coverage fast, here we are still at <strong>93%</strong>. Not perfect, but solid for not much time spent.</p><p>One core learning: Stick with <strong>unit tests </strong>inside <em>/src</em>. Then your tests are compact, simple to maintain and fast to extend. There all the dependency injection actually shows it’s main benefit -&gt; It is super easy to replace and mock logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*-y4UER2uFOC1okwAr9Px3Q.png" /></figure><p>As you see, we mock all our dependencies. Not because it is the clean way to do unit tests, but with NestJS this is actually the efficient way to got. Classes with dependencies injected in the constructor are meant to be mocked.</p><p>We use mock factories a lot to keep dummy object generation in a central place. They may not be perfect mocks and are dead simple, but they worked great for us. With the factories we could also keep the any type-hacks out of the actual tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJV3RgSf2e0ckPFN-64zKQ.png" /></figure><p>To check if the things actually work together, NestJS offers <strong>end-to-end tests </strong>based on <a href="https://github.com/visionmedia/supertest">supertest</a>. Those actually load your app and run HTTP requests against endpoints of your choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6J6M0zk8SfOFK3Y9Skrd3Q.png" /></figure><p>We expect at least one test per controller action, so we also added a coverage test to ensure that.</p><blockquote>Tip #4: Make tests something you just do. You should be able to write the basics without thinking. Follow a pattern, use shared mock factories and use the basics NestJS suggests when it generates services, controllers etc.</blockquote><p>And one more this time:</p><blockquote>Tip #5: Use automation hacks, wherever you can. Be it a simple coverage test or a local eslint rule. Those things are dead simple to write and save you a lot of pain later on. Especially nice are also eslint fixers that take care of sorting decorators in a fixed way. No need to waste manual time on that.</blockquote><h3>Where are my benefits?</h3><p>So, the basics are there, time to add some dev-benefits. Nothing fancy here. Follow the guide and enjoy a solid setup that you wont hate after a week. That’s it.</p><p>Did I mention the amazing <a href="https://docs.nestjs.com/">NestJS docs</a>? 📕</p><p>This are the guides we picked:</p><ul><li><a href="https://docs.nestjs.com/techniques/configuration">Configuration</a>: Access env variables (including .env)</li><li><a href="https://docs.nestjs.com/techniques/validation">Validation</a>: Validate and transform the request data using decorators in your DTOs (based on <a href="https://github.com/typestack/class-validator">class-validator</a> and <a href="https://github.com/typestack/class-transformer">class-transformer</a>)</li><li><a href="https://docs.nestjs.com/techniques/serialization">Serialisation</a>: Transform your DTOs / entities to JSON using decorators (based on <a href="https://github.com/typestack/class-transformer">class-transformer</a>)</li><li><a href="https://docs.nestjs.com/techniques/security">Security</a>: Simple and safe</li><li><a href="https://docs.nestjs.com/techniques/logger">Logging</a>: Well… to log stuff 😄</li><li><a href="https://docs.nestjs.com/techniques/http-module">HTTP</a>: A NestJS friendly <a href="https://github.com/axios/axios">Axios</a> setup</li><li><a href="https://docs.nestjs.com/recipes/swagger">OpenAPI</a> (Swagger): OpenAPI spec based on your DTOs / entities using decorators &lt;- You see a pattern already? 😉</li></ul><p>This gives you a lot of the NestJS goodies that make your life easier. As always, nothing mandatory, pick your own tool. But always have a look at the NestJS packages. They use solid libraries under the hook that might also help you for your customised setup.</p><p>What you will notice: A lot of these libraries work with annotations / decorators. NestJS uses a declarative approach for many things without loosing typings. They really make TypeScript shine and make all those type definitions worth your effort. Easier to motivate yourself to do it, if you know it also gives you validation, serialisation and API specs.</p><blockquote>Tip #6: Always check the guides before building something yourself. Usually you find a solid default option there for your problem.</blockquote><h3>Our journey till now</h3><p>So this wraps up our first steps into the NestJS world. We went a long road from there and faced many more challenges (like TypeORM). But it was really impressive how fast we managed to setup a solid foundation without hating ourselves a couple weeks later.</p><p>What we love most about NestJS is that it brings out the best in people. It makes it easy to write clean code, so you just do it. And with the guides you don’t just get a dummy solution like with many other frameworks, you get something actually production ready.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32faa82f3d4b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/limehome-engineering/getting-started-nestjs-32faa82f3d4b">Getting Started with NestJS</a> was originally published in <a href="https://medium.com/limehome-engineering">limehome-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>