Fireship · @fireship
NestJS in 100 Seconds
Uploaded July 30, 2021 · Length 2:21
Summary
NestJS framework for building scalable server-side applications with TypeScript.
- nestjs
- typescript
- nodejs
- server-side
- framework
- scalability
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
nest js is a node.js framework for
- 0:02
building scalable server-side
- 0:04
applications with typescript it provides
- 0:06
a suite of tools that leverage either
- 0:08
fastify or express to facilitate
- 0:10
rapid development and predictable
- 0:12
readable code it supports rest and
- 0:14
graphql apis out of the box or you might
- 0:16
use it to build a full stack application
- 0:19
using the model view controller pattern
- 0:21
similar to frameworks like laravel
- 0:23
or ruby on rails and it contains a ton
- 0:25
of built-in modules to work with
- 0:26
databases
- 0:27
handle security implement streaming and
- 0:29
anything else you can imagine doing in a
- 0:31
server side application
- 0:32
nest has its own very powerful command
- 0:34
line tool and you can scaffold out a new
- 0:36
project with the nest
- 0:37
new command that provides a code base
- 0:39
pre-configured with jest for testing and
- 0:41
set up with typescript to help us write
- 0:43
more readable and reliable code in the
- 0:45
source directory you'll notice a
- 0:46
controller which is a fundamental
- 0:48
building block of the framework
- 0:49
it's responsible for handling incoming
- 0:51
http requests
- 0:52
and returning responses back to the
- 0:54
client to implement a controller simply
- 0:56
add the controller decorator
- 0:58
to a class then inside the class you can
- 1:00
implement methods
- 1:01
and decorate them with http verbs like
- 1:03
git
- 1:04
post patch put etc by default this will
- 1:07
create an http endpoint on the root url
- 1:09
but you can pass a string to the
- 1:11
decorator to
- 1:12
change the route or implement dynamic
- 1:14
route parameters in addition
- 1:15
nest provides other decorators to
- 1:17
control things like the status code and
- 1:19
headers then
- 1:20
in the method itself parameter
- 1:21
decorators can be used to access the
- 1:23
request parameters or body
- 1:25
and finally the return value from the
- 1:27
method is the response body
- 1:28
that gets sent back down to the client
- 1:30
what's awesome about nest
- 1:32
is that you can use the cli to
- 1:33
automatically generate more controllers
- 1:35
to keep your code organized as it grows
- 1:37
in complexity
- 1:38
but there's more to nest than just
- 1:39
controllers a provider is a class that
- 1:42
contains shared logic throughout the
- 1:43
entire application
- 1:44
and can be injected as a dependency
- 1:46
where needed any class with the
- 1:48
injectable decorator can be injected in
- 1:49
the constructor of another class
- 1:51
for example a provider can be
- 1:53
implemented as a guard to handle
- 1:55
role-based user authentication
- 1:56
or it might be implemented as a pipe to
- 1:59
efficiently validate and transform


