A quick setup guide 🍳 for NestJS and Firebase Cloud Functions. Two strategies for making your Nest app serverless in the first episode of  *The More you Code*. https://fireship.io/snippets/setup-nestjs-on-cloud-functions/

#nest #js #serverless

Don't forget to take the quiz 🤓

iOS https://itunes.apple.com/us/app/fireship/id1462592372?mt=8
Android https://play.google.com/store/apps/details?id=io.fireship.quizapp

Upgrade to Fireship PRO at https://fireship.io/pro
Use code lORhwXd2 for 25% off your first payment.
2024-02-04T06:36:04.547Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
e5c7a87d-34ed-4db8-8c99-3ae44fd8a622
6a327c1f56b56ce8138f225f5aae5c7fa6fad3f982af99fabe15974ced634a23
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
NestJS and Firebase Cloud Functions.
Both are awesome tools for node developers, and today you'll learn how to combine the 2 together.
But first, I'd like to welcome you to a new series called The More You Code, where we'll cover highly specialized topics in about 2 to 3 minutes.
And the reason I'm creating this series is because I have a massive list of video ideas that just don't really fit into the ten Into 15 minute format that YouTube prefers.
So rather than be a slave to the YouTube algorithm, I'm going to release some shorter videos that hopefully you find useful.
So So let me know what you think about that idea in the comments because I'll be giving away another t shirt with this video.
And congrats to Paul Boma who is last week's winner.
Know.
So let's just go ahead and get right into it.
We have Nest, which is a Node.
Js framework for building scalable server side applications.
And then we have Cloud Functions, which is the actual infrastructure that allows a server side application to scale infinitely.
Sounds like a pretty good match if you ask me.
So let's look at 2 different ways we can combine these 2 technologies together.
Friends who ride majestic, translucent steeds, shooting flaming arrows across the bridge of Emden.
I would follow you into the mists of Avalon, if that's what you mean.
The first option we'll look at starts with a Nest application and then brings in Cloud Functions.
The second option will do the exact opposite, start with a functions project, and then bring in Nest.
So this first option is ideal if you have an existing Nest app that you want to deploy to Cloud So we'll go ahead and generate a new Nest application.
Then from the parent directory, we'll go ahead and initialize Firebase functions.
We don't actually want the functions directory, 3, so just go ahead and delete it.
Now by default, the Firebase functions environment will be looking for the functions directory.
So we'll want to go into the Firebase JSON and change the source 2 Server or whatever the name of your Nest application is.
And then we'll want to install the dependencies that we would normally use in the functions environment, like Firebase functions, admin, Utespress and then also NestJS Platform Express.
Now when Cloud Functions attempts to run your code, it will be looking for the main field in the package JSON, And we'll set that up as the dist index.
Js file.
And then you'll also want to set the node engine to 8 or 10 or whatever version you wanna use.
From there, we need to create the actual server, and we'll do that inside the source directory in this index dot ts file.
In this file, we'll create an instance of an Express app, and then we'll write a function called create Nest Server, and its responsibility is to wrap that Express app with our app module in Nest.
Then we'll go ahead and call this function, and it returns a promise, so we'll want to make sure to handle it with then and catch.
And then the last step is just to export the Cloud Function, which we'll go ahead and call API, and it's just a Firebase HTTPS function that takes the express app as its argument.
And that's all there is to it.
We can now compile the server with npm run build.
That will generate the dist folder, and then we can run Firebase serve only functions to serve the functions locally or deploy them with Firebase deploy only functions.
Then you should be able to make a request to that URL and get a response from the Nest application.
Now one thing that I'll mention is that this whole process could be made a lot easier if someone developed a schematic for this.
Not that the setup is all that hard, but Azure Functions already have a Ukematic that allow you to handle all the setup with a single command, and that makes me kind of jealous as someone who primarily uses GCP.
But let's go ahead and move on to the second setup strategy.
You may have an existing Firebase project that already has its own background functions, and you want to add nest to that project for your HTTP functions.
In that case, you would go into the functions directory and manually install the nest dependencies.
And then you'd likely want to create a nest cli.
Json file in the functions agree to use the nest CLI to automatically generate your code.
And as you can see here, I can now call nest generate for an app module and a controller.
But at this point, we'll get some errors because the Cloud Functions environment doesn't have things like decorators enabled by default.
We can fix that by going to the ts config, and then we'll add the options that would normally be present in a nest app.
From there, we'll go into the index.
Ts file and write the same exact code that we wrote in the previous example.
And now we can run npm run serve to serve the functions locally or Firebase deploy only functions to deploy them.
And that gives you another option to set up NestJS with Cloud Functions.
What?
Did we just become best friends?
Yep.
I'm gonna go ahead and wrap things up there, but you can expect more Ness content in the near future.
If this video helped you, please like and subscribe and consider becoming a pro member at FireShip.
Io.
Thanks for watching and I will talk to you soon.

Speaker 0: NestJS and Firebase Cloud Functions. Both are awesome tools for node developers, and today you'll learn how to combine the 2 together. But first, I'd like to welcome you to a new series called The More You Code, where we'll cover highly specialized topics in about 2 to 3 minutes. And the reason I'm creating this series is because I have a massive list of video ideas that just don't really fit into the ten Into 15 minute format that YouTube prefers. So rather than be a slave to the YouTube algorithm, I'm going to release some shorter videos that hopefully you find useful.

So So let me know what you think about that idea in the comments because I'll be giving away another t shirt with this video. And congrats to Paul Boma who is last week's winner. Know. So let's just go ahead and get right into it. We have Nest, which is a Node.

Js framework for building scalable server side applications. And then we have Cloud Functions, which is the actual infrastructure that allows a server side application to scale infinitely. Sounds like a pretty good match if you ask me. So let's look at 2 different ways we can combine these 2 technologies together. Friends who ride majestic, translucent steeds, shooting flaming arrows across the bridge of Emden.

I would follow you into the mists of Avalon, if that's what you mean. The first option we'll look at starts with a Nest application and then brings in Cloud Functions. The second option will do the exact opposite, start with a functions project, and then bring in Nest. So this first option is ideal if you have an existing Nest app that you want to deploy to Cloud So we'll go ahead and generate a new Nest application. Then from the parent directory, we'll go ahead and initialize Firebase functions.

We don't actually want the functions directory, 3, so just go ahead and delete it. Now by default, the Firebase functions environment will be looking for the functions directory. So we'll want to go into the Firebase JSON and change the source 2 Server or whatever the name of your Nest application is. And then we'll want to install the dependencies that we would normally use in the functions environment, like Firebase functions, admin, Utespress and then also NestJS Platform Express. Now when Cloud Functions attempts to run your code, it will be looking for the main field in the package JSON, And we'll set that up as the dist index.

Js file. And then you'll also want to set the node engine to 8 or 10 or whatever version you wanna use. From there, we need to create the actual server, and we'll do that inside the source directory in this index dot ts file. In this file, we'll create an instance of an Express app, and then we'll write a function called create Nest Server, and its responsibility is to wrap that Express app with our app module in Nest. Then we'll go ahead and call this function, and it returns a promise, so we'll want to make sure to handle it with then and catch.

And then the last step is just to export the Cloud Function, which we'll go ahead and call API, and it's just a Firebase HTTPS function that takes the express app as its argument. And that's all there is to it. We can now compile the server with npm run build. That will generate the dist folder, and then we can run Firebase serve only functions to serve the functions locally or deploy them with Firebase deploy only functions. Then you should be able to make a request to that URL and get a response from the Nest application.

Now one thing that I'll mention is that this whole process could be made a lot easier if someone developed a schematic for this. Not that the setup is all that hard, but Azure Functions already have a Ukematic that allow you to handle all the setup with a single command, and that makes me kind of jealous as someone who primarily uses GCP. But let's go ahead and move on to the second setup strategy. You may have an existing Firebase project that already has its own background functions, and you want to add nest to that project for your HTTP functions. In that case, you would go into the functions directory and manually install the nest dependencies.

And then you'd likely want to create a nest cli. Json file in the functions agree to use the nest CLI to automatically generate your code. And as you can see here, I can now call nest generate for an app module and a controller. But at this point, we'll get some errors because the Cloud Functions environment doesn't have things like decorators enabled by default. We can fix that by going to the ts config, and then we'll add the options that would normally be present in a nest app.

From there, we'll go into the index. Ts file and write the same exact code that we wrote in the previous example. And now we can run npm run serve to serve the functions locally or Firebase deploy only functions to deploy them. And that gives you another option to set up NestJS with Cloud Functions. What?

Did we just become best friends? Yep. I'm gonna go ahead and wrap things up there, but you can expect more Ness content in the near future. If this video helped you, please like and subscribe and consider becoming a pro member at FireShip. Io.

Thanks for watching and I will talk to you soon.
NestJS and Firebase Cloud Functions. Both are awesome tools for node developers, and today you'll learn how to combine the 2 together. But first, I'd like to welcome you to a new series called The More You Code, where we'll cover highly specialized topics in about 2 to 3 minutes.
And the reason I'm creating this series is because I have a massive list of video ideas that just don't really fit into the ten Into 15 minute format that YouTube prefers. So rather than be a slave to the YouTube algorithm, I'm going to release some shorter videos that hopefully you find useful. So So let me know what you think about that idea in the comments because I'll be giving away another t shirt with this video. And congrats to Paul Boma who is last week's winner.
youtube
video gaming
Know. So let's just go ahead and get right into it. We have Nest, which is a Node.
Js framework for building scalable server side applications. And then we have Cloud Functions, which is the actual infrastructure that allows a server side application to scale infinitely. Sounds like a pretty good match if you ask me. So let's look at 2 different ways we can combine these 2 technologies together.
infrastructure
Friends who ride majestic, translucent steeds, shooting flaming arrows across the bridge of Emden. I would follow you into the mists of Avalon, if that's what you mean. The first option we'll look at starts with a Nest application and then brings in Cloud Functions. The second option will do the exact opposite, start with a functions project, and then bring in Nest. So this first option is ideal if you have an existing Nest app that you want to deploy to Cloud So we'll go ahead and generate a new Nest application. Then from the parent directory, we'll go ahead and initialize Firebase functions. We don't actually want the functions directory, 3, so just go ahead and delete it. Now by default, the Firebase functions environment will be looking for the functions directory. So we'll want to go into the Firebase JSON and change the source 2 Server or whatever the name of your Nest application is. And then we'll want to install the dependencies that we would normally use in the functions environment, like Firebase functions, admin, Utespress and then also NestJS Platform Express. Now when Cloud Functions attempts to run your code, it will be looking for the main field in the package JSON, And we'll set that up as the dist index. Js file. And then you'll also want to set the node engine to 8 or 10 or whatever version you wanna use. From there, we need to create the actual server, and we'll do that inside the source directory in this index dot ts file.
In this file, we'll create an instance of an Express app, and then we'll write a function called create Nest Server, and its responsibility is to wrap that Express app with our app module in Nest. Then we'll go ahead and call this function, and it returns a promise, so we'll want to make sure to handle it with then and catch.
programming
And then the last step is just to export the Cloud Function, which we'll go ahead and call API, and it's just a Firebase HTTPS function that takes the express app as its argument. And that's all there is to it. We can now compile the server with npm run build. That will generate the dist folder, and then we can run Firebase serve only functions to serve the functions locally or deploy them with Firebase deploy only functions. Then you should be able to make a request to that URL and get a response from the Nest application. Now one thing that I'll mention is that this whole process could be made a lot easier if someone developed a schematic for this. Not that the setup is all that hard, but Azure Functions already have a Ukematic that allow you to handle all the setup with a single command, and that makes me kind of jealous as someone who primarily uses GCP. But let's go ahead and move on to the second setup strategy. You may have an existing Firebase project that already has its own background functions, and you want to add nest to that project for your HTTP functions. In that case, you would go into the functions directory and manually install the nest dependencies. And then you'd likely want to create a nest cli. Json file in the functions agree to use the nest CLI to automatically generate your code. And as you can see here, I can now call nest generate for an app module and a controller. But at this point, we'll get some errors because the Cloud Functions environment doesn't have things like decorators enabled by default. We can fix that by going to the ts config, and then we'll add the options that would normally be present in a nest app. From there, we'll go into the index. Ts file and write the same exact code that we wrote in the previous example. And now we can run npm run serve to serve the functions locally or Firebase deploy only functions to deploy them. And that gives you another option to set up NestJS with Cloud Functions. What? Did we just become best friends? Yep. I'm gonna go ahead and wrap things up there, but you can expect more Ness content in the near future.
If this video helped you, please like and subscribe and consider becoming a pro member at FireShip. Io. Thanks for watching and I will talk to you soon.
youtube
NestJS and Firebase Cloud Functions. Both are awesome tools for node developers, and today you'll learn how to combine the 2 together. But first, I'd like to welcome you to a new series called The More You Code, where we'll cover highly specialized topics in about 2 to 3 minutes. And the reason I'm creating this series is because I have a massive list of video ideas that just don't really fit into the ten Into 15 minute format that YouTube prefers. So rather than be a slave to the YouTube algorithm, I'm going to release some shorter videos that hopefully you find useful. So So let me know what you think about that idea in the comments because I'll be giving away another t shirt with this video. And congrats to Paul Boma who is last week's winner. Know. So let's just go ahead and get right into it. We have Nest, which is a Node. Js framework for building scalable server side applications. And then we have Cloud Functions, which is the actual infrastructure that allows a server side application to scale infinitely. Sounds like a pretty good match if you ask me. So let's look at 2 different ways we can combine these 2 technologies together. Friends who ride majestic, translucent steeds, shooting flaming arrows across the bridge of Emden. I would follow you into the mists of Avalon, if that's what you mean. The first option we'll look at starts with a Nest application and then brings in Cloud Functions. The second option will do the exact opposite, start with a functions project, and then bring in Nest. So this first option is ideal if you have an existing Nest app that you want to deploy to Cloud So we'll go ahead and generate a new Nest application. Then from the parent directory, we'll go ahead and initialize Firebase functions. We don't actually want the functions directory, 3, so just go ahead and delete it. Now by default, the Firebase functions environment will be looking for the functions directory. So we'll want to go into the Firebase JSON and change the source 2 Server or whatever the name of your Nest application is. And then we'll want to install the dependencies that we would normally use in the functions environment, like Firebase functions, admin, Utespress and then also NestJS Platform Express. Now when Cloud Functions attempts to run your code, it will be looking for the main field in the package JSON, And we'll set that up as the dist index. Js file. And then you'll also want to set the node engine to 8 or 10 or whatever version you wanna use. From there, we need to create the actual server, and we'll do that inside the source directory in this index dot ts file. In this file, we'll create an instance of an Express app, and then we'll write a function called create Nest Server, and its responsibility is to wrap that Express app with our app module in Nest. Then we'll go ahead and call this function, and it returns a promise, so we'll want to make sure to handle it with then and catch. And then the last step is just to export the Cloud Function, which we'll go ahead and call API, and it's just a Firebase HTTPS function that takes the express app as its argument. And that's all there is to it. We can now compile the server with npm run build. That will generate the dist folder, and then we can run Firebase serve only functions to serve the functions locally or deploy them with Firebase deploy only functions. Then you should be able to make a request to that URL and get a response from the Nest application. Now one thing that I'll mention is that this whole process could be made a lot easier if someone developed a schematic for this. Not that the setup is all that hard, but Azure Functions already have a Ukematic that allow you to handle all the setup with a single command, and that makes me kind of jealous as someone who primarily uses GCP. But let's go ahead and move on to the second setup strategy. You may have an existing Firebase project that already has its own background functions, and you want to add nest to that project for your HTTP functions. In that case, you would go into the functions directory and manually install the nest dependencies. And then you'd likely want to create a nest cli. Json file in the functions agree to use the nest CLI to automatically generate your code. And as you can see here, I can now call nest generate for an app module and a controller. But at this point, we'll get some errors because the Cloud Functions environment doesn't have things like decorators enabled by default. We can fix that by going to the ts config, and then we'll add the options that would normally be present in a nest app. From there, we'll go into the index. Ts file and write the same exact code that we wrote in the previous example. And now we can run npm run serve to serve the functions locally or Firebase deploy only functions to deploy them. And that gives you another option to set up NestJS with Cloud Functions. What? Did we just become best friends? Yep. I'm gonna go ahead and wrap things up there, but you can expect more Ness content in the near future. If this video helped you, please like and subscribe and consider becoming a pro member at FireShip. Io. Thanks for watching and I will talk to you soon.
NestJS
nestjs
and
and
Firebase
firebase
Cloud
cloud
Functions.
functions
Both
both
are
are
awesome
awesome
tools
tools
for
for
node
node
developers,
developers
and
and
today
today
you'll
you'll
learn
learn
how
how
to
to
combine
combine
the
the
2
2
together.
together
But
but
first,
first
I'd
i'd
like
like
to
to
welcome
welcome
you
you
to
to
a
a
new
new
series
series
called
called
The
the
More
more
You
you
Code,
code
where
where
we'll
we'll
cover
cover
highly
highly
specialized
specialized
topics
topics
in
in
about
about
2
2
to
to
3
3
minutes.
minutes
And
and
the
the
reason
reason
I'm
i'm
creating
creating
this
this
series
series
is
is
because
because
I
i
have
have
a
a
massive
massive
list
list
of
of
video
video
ideas
ideas
that
that
just
just
don't
don't
really
really
fit
fit
into
into
the
the
ten
ten
Into
into
15
15
minute
minute
format
format
that
that
YouTube
youtube
prefers.
prefers
So
so
rather
rather
than
than
be
be
a
a
slave
slave
to
to
the
the
YouTube
youtube
algorithm,
algorithm
I'm
i'm
going
going
to
to
release
release
some
some
shorter
shorter
videos
videos
that
that
hopefully
hopefully
you
you
find
find
useful.
useful
So
so
So
so
let
let
me
me
know
know
what
what
you
you
think
think
about
about
that
that
idea
idea
in
in
the
the
comments
comments
because
because
I'll
i'll
be
be
giving
giving
away
away
another
another
t
t
shirt
shirt
with
with
this
this
video.
video
And
and
congrats
congrats
to
to
Paul
paul
Boma
boma
who
who
is
is
last
last
week's
week's
winner.
winner
Know.
know
So
so
let's
let's
just
just
go
go
ahead
ahead
and
and
get
get
right
right
into
into
it.
it
We
we
have
have
Nest,
nest
which
which
is
is
a
a
Node.
node
Js
js
framework
framework
for
for
building
building
scalable
scalable
server
server
side
side
applications.
applications
And
and
then
then
we
we
have
have
Cloud
cloud
Functions,
functions
which
which
is
is
the
the
actual
actual
infrastructure
infrastructure
that
that
allows
allows
a
a
server
server
side
side
application
application
to
to
scale
scale
infinitely.
infinitely
Sounds
sounds
like
like
a
a
pretty
pretty
good
good
match
match
if
if
you
you
ask
ask
me.
me
So
so
let's
let's
look
look
at
at
2
2
different
different
ways
ways
we
we
can
can
combine
combine
these
these
2
2
technologies
technologies
together.
together
Friends
friends
who
who
ride
ride
majestic,
majestic
translucent
translucent
steeds,
steeds
shooting
shooting
flaming
flaming
arrows
arrows
across
across
the
the
bridge
bridge
of
of
Emden.
emden
I
i
would
would
follow
follow
you
you
into
into
the
the
mists
mists
of
of
Avalon,
avalon
if
if
that's
that's
what
what
you
you
mean.
mean
The
the
first
first
option
option
we'll
we'll
look
look
at
at
starts
starts
with
with
a
a
Nest
nest
application
application
and
and
then
then
brings
brings
in
in
Cloud
cloud
Functions.
functions
The
the
second
second
option
option
will
will
do
do
the
the
exact
exact
opposite,
opposite
start
start
with
with
a
a
functions
functions
project,
project
and
and
then
then
bring
bring
in
in
Nest.
nest
So
so
this
this
first
first
option
option
is
is
ideal
ideal
if
if
you
you
have
have
an
an
existing
existing
Nest
nest
app
app
that
that
you
you
want
want
to
to
deploy
deploy
to
to
Cloud
cloud
So
so
we'll
we'll
go
go
ahead
ahead
and
and
generate
generate
a
a
new
new
Nest
nest
application.
application
Then
then
from
from
the
the
parent
parent
directory,
directory
we'll
we'll
go
go
ahead
ahead
and
and
initialize
initialize
Firebase
firebase
functions.
functions
We
we
don't
don't
actually
actually
want
want
the
the
functions
functions
directory,
directory
3,
3
so
so
just
just
go
go
ahead
ahead
and
and
delete
delete
it.
it
Now
now
by
by
default,
default
the
the
Firebase
firebase
functions
functions
environment
environment
will
will
be
be
looking
looking
for
for
the
the
functions
functions
directory.
directory
So
so
we'll
we'll
want
want
to
to
go
go
into
into
the
the
Firebase
firebase
JSON
json
and
and
change
change
the
the
source
source
2
2
Server
server
or
or
whatever
whatever
the
the
name
name
of
of
your
your
Nest
nest
application
application
is.
is
And
and
then
then
we'll
we'll
want
want
to
to
install
install
the
the
dependencies
dependencies
that
that
we
we
would
would
normally
normally
use
use
in
in
the
the
functions
functions
environment,
environment
like
like
Firebase
firebase
functions,
functions
admin,
admin
Utespress
utespress
and
and
then
then
also
also
NestJS
nestjs
Platform
platform
Express.
express
Now
now
when
when
Cloud
cloud
Functions
functions
attempts
attempts
to
to
run
run
your
your
code,
code
it
it
will
will
be
be
looking
looking
for
for
the
the
main
main
field
field
in
in
the
the
package
package
JSON,
json
And
and
we'll
we'll
set
set
that
that
up
up
as
as
the
the
dist
dist
index.
index
Js
js
file.
file
And
and
then
then
you'll
you'll
also
also
want
want
to
to
set
set
the
the
node
node
engine
engine
to
to
8
8
or
or
10
10
or
or
whatever
whatever
version
version
you
you
wanna
wanna
use.
use
From
from
there,
there
we
we
need
need
to
to
create
create
the
the
actual
actual
server,
server
and
and
we'll
we'll
do
do
that
that
inside
inside
the
the
source
source
directory
directory
in
in
this
this
index
index
dot
dot
ts
ts
file.
file
In
in
this
this
file,
file
we'll
we'll
create
create
an
an
instance
instance
of
of
an
an
Express
express
app,
app
and
and
then
then
we'll
we'll
write
write
a
a
function
function
called
called
create
create
Nest
nest
Server,
server
and
and
its
its
responsibility
responsibility
is
is
to
to
wrap
wrap
that
that
Express
express
app
app
with
with
our
our
app
app
module
module
in
in
Nest.
nest
Then
then
we'll
we'll
go
go
ahead
ahead
and
and
call
call
this
this
function,
function
and
and
it
it
returns
returns
a
a
promise,
promise
so
so
we'll
we'll
want
want
to
to
make
make
sure
sure
to
to
handle
handle
it
it
with
with
then
then
and
and
catch.
catch
And
and
then
then
the
the
last
last
step
step
is
is
just
just
to
to
export
export
the
the
Cloud
cloud
Function,
function
which
which
we'll
we'll
go
go
ahead
ahead
and
and
call
call
API,
api
and
and
it's
it's
just
just
a
a
Firebase
firebase
HTTPS
https
function
function
that
that
takes
takes
the
the
express
express
app
app
as
as
its
its
argument.
argument
And
and
that's
that's
all
all
there
there
is
is
to
to
it.
it
We
we
can
can
now
now
compile
compile
the
the
server
server
with
with
npm
npm
run
run
build.
build
That
that
will
will
generate
generate
the
the
dist
dist
folder,
folder
and
and
then
then
we
we
can
can
run
run
Firebase
firebase
serve
serve
only
only
functions
functions
to
to
serve
serve
the
the
functions
functions
locally
locally
or
or
deploy
deploy
them
them
with
with
Firebase
firebase
deploy
deploy
only
only
functions.
functions
Then
then
you
you
should
should
be
be
able
able
to
to
make
make
a
a
request
request
to
to
that
that
URL
url
and
and
get
get
a
a
response
response
from
from
the
the
Nest
nest
application.
application
Now
now
one
one
thing
thing
that
that
I'll
i'll
mention
mention
is
is
that
that
this
this
whole
whole
process
process
could
could
be
be
made
made
a
a
lot
lot
easier
easier
if
if
someone
someone
developed
developed
a
a
schematic
schematic
for
for
this.
this
Not
not
that
that
the
the
setup
setup
is
is
all
all
that
that
hard,
hard
but
but
Azure
azure
Functions
functions
already
already
have
have
a
a
Ukematic
ukematic
that
that
allow
allow
you
you
to
to
handle
handle
all
all
the
the
setup
setup
with
with
a
a
single
single
command,
command
and
and
that
that
makes
makes
me
me
kind
kind
of
of
jealous
jealous
as
as
someone
someone
who
who
primarily
primarily
uses
uses
GCP.
gcp
But
but
let's
let's
go
go
ahead
ahead
and
and
move
move
on
on
to
to
the
the
second
second
setup
setup
strategy.
strategy
You
you
may
may
have
have
an
an
existing
existing
Firebase
firebase
project
project
that
that
already
already
has
has
its
its
own
own
background
background
functions,
functions
and
and
you
you
want
want
to
to
add
add
nest
nest
to
to
that
that
project
project
for
for
your
your
HTTP
http
functions.
functions
In
in
that
that
case,
case
you
you
would
would
go
go
into
into
the
the
functions
functions
directory
directory
and
and
manually
manually
install
install
the
the
nest
nest
dependencies.
dependencies
And
and
then
then
you'd
you'd
likely
likely
want
want
to
to
create
create
a
a
nest
nest
cli.
cli
Json
json
file
file
in
in
the
the
functions
functions
agree
agree
to
to
use
use
the
the
nest
nest
CLI
cli
to
to
automatically
automatically
generate
generate
your
your
code.
code
And
and
as
as
you
you
can
can
see
see
here,
here
I
i
can
can
now
now
call
call
nest
nest
generate
generate
for
for
an
an
app
app
module
module
and
and
a
a
controller.
controller
But
but
at
at
this
this
point,
point
we'll
we'll
get
get
some
some
errors
errors
because
because
the
the
Cloud
cloud
Functions
functions
environment
environment
doesn't
doesn't
have
have
things
things
like
like
decorators
decorators
enabled
enabled
by
by
default.
default
We
we
can
can
fix
fix
that
that
by
by
going
going
to
to
the
the
ts
ts
config,
config
and
and
then
then
we'll
we'll
add
add
the
the
options
options
that
that
would
would
normally
normally
be
be
present
present
in
in
a
a
nest
nest
app.
app
From
from
there,
there
we'll
we'll
go
go
into
into
the
the
index.
index
Ts
ts
file
file
and
and
write
write
the
the
same
same
exact
exact
code
code
that
that
we
we
wrote
wrote
in
in
the
the
previous
previous
example.
example
And
and
now
now
we
we
can
can
run
run
npm
npm
run
run
serve
serve
to
to
serve
serve
the
the
functions
functions
locally
locally
or
or
Firebase
firebase
deploy
deploy
only
only
functions
functions
to
to
deploy
deploy
them.
them
And
and
that
that
gives
gives
you
you
another
another
option
option
to
to
set
set
up
up
NestJS
nestjs
with
with
Cloud
cloud
Functions.
functions
What?
what
Did
did
we
we
just
just
become
become
best
best
friends?
friends
Yep.
yep
I'm
i'm
gonna
gonna
go
go
ahead
ahead
and
and
wrap
wrap
things
things
up
up
there,
there
but
but
you
you
can
can
expect
expect
more
more
Ness
ness
content
content
in
in
the
the
near
near
future.
future
If
if
this
this
video
video
helped
helped
you,
you
please
please
like
like
and
and
subscribe
subscribe
and
and
consider
consider
becoming
becoming
a
a
pro
pro
member
member
at
at
FireShip.
fireship
Io.
io
Thanks
thanks
for
for
watching
watching
and
and
I
i
will
will
talk
talk
to
to
you
you
soon.
soon
success
The speaker introduces a series on how to combine NestJS and Guinea Cloud reminded to the audience. They explain the process for creating a single Nest application and integrating CloudGeneration, and provide a demonstration of how to use it in the Cloud Function environment. They also discuss the setup strategy for using the Cloud Function environment and suggest a schematic for setting up the Nest OS.
Nest on Cloud Functions
NestJS and Firebase Cloud Functions. Both are awesome tools for node developers, and today you'll learn how to combine the 2 together. But first, I'd like to welcome you to a new series called The More You Code, where we'll cover highly specialized topics in about 2 to 3 minutes. And the reason I'm creating this series is because I have a massive list of video ideas that just don't really fit into the ten Into 15 minute format that YouTube prefers. So rather than be a slave to the YouTube algorithm, I'm going to release some shorter videos that hopefully you find useful. So So let me know what you think about that idea in the comments because I'll be giving away another t shirt with this video. And congrats to Paul Boma who is last week's winner. Know. So let's just go ahead and get right into it. We have Nest, which is a Node. Js framework for building scalable server side applications. And then we have Cloud Functions, which is the actual infrastructure that allows a server side application to scale infinitely. Sounds like a pretty good match if you ask me. So let's look at 2 different ways we can combine these 2 technologies together. Friends who ride majestic, translucent steeds, shooting flaming arrows across the bridge of Emden. I would follow you into the mists of Avalon, if that's what you mean. The first option we'll look at starts with a Nest application and then brings in Cloud Functions. The second option will do the exact opposite, start with a functions project, and then bring in Nest. So this first option is ideal if you have an existing Nest app that you want to deploy to Cloud So we'll go ahead and generate a new Nest application. Then from the parent directory, we'll go ahead and initialize Firebase functions. We don't actually want the functions directory, 3, so just go ahead and delete it. Now by default, the Firebase functions environment will be looking for the functions directory. So we'll want to go into the Firebase JSON and change the source 2 Server or whatever the name of your Nest application is. And then we'll want to install the dependencies that we would normally use in the functions environment, like Firebase functions, admin, Utespress and then also NestJS Platform Express. Now when Cloud Functions attempts to run your code, it will be looking for the main field in the package JSON, And we'll set that up as the dist index. Js file. And then you'll also want to set the node engine to 8 or 10 or whatever version you wanna use. From there, we need to create the actual server, and we'll do that inside the source directory in this index dot ts file. In this file, we'll create an instance of an Express app, and then we'll write a function called create Nest Server, and its responsibility is to wrap that Express app with our app module in Nest. Then we'll go ahead and call this function, and it returns a promise, so we'll want to make sure to handle it with then and catch. And then the last step is just to export the Cloud Function, which we'll go ahead and call API, and it's just a Firebase HTTPS function that takes the express app as its argument. And that's all there is to it. We can now compile the server with npm run build. That will generate the dist folder, and then we can run Firebase serve only functions to serve the functions locally or deploy them with Firebase deploy only functions. Then you should be able to make a request to that URL and get a response from the Nest application. Now one thing that I'll mention is that this whole process could be made a lot easier if someone developed a schematic for this. Not that the setup is all that hard, but Azure Functions already have a Ukematic that allow you to handle all the setup with a single command, and that makes me kind of jealous as someone who primarily uses GCP. But let's go ahead and move on to the second setup strategy. You may have an existing Firebase project that already has its own background functions, and you want to add nest to that project for your HTTP functions. In that case, you would go into the functions directory and manually install the nest dependencies. And then you'd likely want to create a nest cli. Json file in the functions agree to use the nest CLI to automatically generate your code. And as you can see here, I can now call nest generate for an app module and a controller. But at this point, we'll get some errors because the Cloud Functions environment doesn't have things like decorators enabled by default. We can fix that by going to the ts config, and then we'll add the options that would normally be present in a nest app. From there, we'll go into the index. Ts file and write the same exact code that we wrote in the previous example. And now we can run npm run serve to serve the functions locally or Firebase deploy only functions to deploy them. And that gives you another option to set up NestJS with Cloud Functions. What? Did we just become best friends? Yep. I'm gonna go ahead and wrap things up there, but you can expect more Ness content in the near future. If this video helped you, please like and subscribe and consider becoming a pro member at FireShip. Io. Thanks for watching and I will talk to you soon.
The speaker introduces a series on how to combine NestJS and Guinea Cloud reminded to the audience. They explain the process for creating a single Nest application and integrating CloudGeneration, and provide a demonstration of how to use it in the Cloud Function environment. They also discuss the setup strategy for using the Cloud Function environment and suggest a schematic for setting up the Nest OS.