We already saw that it is really is to develop an REST Api using NestJs, although, how easy is to implement authentication in NestJS using JWT? Spoiler alert: It’s really easy.
First we need to create our nest project. For this step I will a script developed by me that will generate a project with logger and TypeORM connection built in. If you need help to connect TypeORM with NestJS checkout my post about that. If you want know a little bit more about NestJS you can check my other post when I develop a NestJS REST Api from scratch.
This week I was trying to deploy a static page using Heroku, although it wasn’t pretty straightforward… But first things first…
Obs: I will use Visual Studio Code as my text editor, so every line when you see
code . that stands for command line step to open VS Code.
As mentioned on Heroku’s webpage, “Heroku is a cloud platform that lets companies build, deliver, monitor and scale apps — we’re the fastest way to go from idea to URL, bypassing all those infrastructure headaches.”
Let’s create a new project and connect to our repository:
I’m an enthusiast user of Smart Home stuff, a year ago I bought a Xiaomi Yeelight Bulb and recently I decide to use a bit more of his capabilities.
To be able to use the Yeelight library for python we must enable developer mode on our lamp. Go to Yeelight App available on Play Store install it and log into your account.
Open your bulb on your app and at the bottom right press the “eject” icon, this action will open an new menu where you can see “Lan Control”, press that button.
TypeORM is definitely the most mature Object Relational Mapper (ORM) available in the node.js world. Since it’s written in TypeScript, it works pretty well with the Nest framework.
The reference database for this article will be PostgreSQL.
npm install --save @nestjs/typeorm typeorm pg
To deploy our database we will use docker. To do it we simply need to run:
docker pull postgres
docker run --name [container_name] -e POSTGRES_PASSWORD=[database_password] -p 5432:5432 -d postgres
After that we just need to login and create a database:
docker exec -it postgresdb psql -U postgres
create database nestjs;
Now our database is ready to use.
Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. …