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.

Let’s start

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.

What is Heroku?

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.”

Try our first deployment

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.

Let’s get started

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.

Enable Developer Mode

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.

Getting Started

npm install --save @nestjs/typeorm typeorm pg

Deploy Database

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.

Configuration Service

What is NestJS?

As mentioned at NestJS Documentation, Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).

Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!

Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. …

Rui Coelho

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store