Node.js Food Order System Tutorial (EASY & FAST)
Summary
TLDRIn this video, the host guides viewers through deploying a Node.js project on Heroku, explaining the transition to microservices architecture. The tutorial covers project preparation for production, including compiling TypeScript and setting up PM2 for process monitoring. It also introduces DevOps practices, such as Dockerization, Docker Compose, and CI/CD pipelines. The host demonstrates deploying to Heroku, configuring databases, and updating the application with new features, like order handling, ensuring a smooth viewer experience into the next episode focusing on microservices.
Takeaways
- đ The video discusses deploying a Node.js project on Heroku and transitioning to a microservices architecture in subsequent episodes.
- đ ïž The project needs to be built compatible with ES5 or ES6, especially when using TypeScript, to ensure it runs smoothly on the production server.
- đŠ The script covers the importance of Dockerizing the project and its dependencies for independent operations and ease of management.
- đ The video introduces the use of Docker Compose for running containers easily and setting up a Docker network for service communication.
- đ§ The script explains the setup of a CI/CD pipeline for integration testing and deployment automation to the cloud.
- đ The video mentions using a reverse proxy like NGINX for exposing the application to the audience and load balancing with Kubernetes.
- đ The importance of configuring the `package.json` file for deployment is highlighted, including setting up scripts for build and start processes.
- đ The script details modifying the Node.js application to work with environment variables, especially for database connections and port configurations.
- đ The video shows the process of creating and configuring a Heroku app, including pushing code and handling build processes on the platform.
- đ Debugging tips are provided, such as using Heroku logs to monitor the application's behavior and troubleshoot issues.
- đ The script outlines steps for creating order functionalities in the application, including handling order creation and retrieval of order details.
Q & A
What is the main topic discussed in the video script?
-The main topic discussed in the video script is the deployment of a Node.js project on Heroku and the subsequent development of an order section within the project.
Why is the project being deployed on Heroku before the order section is completed?
-The project is being deployed on Heroku early because the tutorial is transitioning to a microservices architecture from the next episode onward, and this allows viewers who are not interested in microservices to continue with the monolithic architecture.
What is the significance of compiling the project's TypeScript to ES5 or ES6 before deployment?
-Compiling TypeScript to ES5 or ES6 is important because running the project directly with TypeScript and development dependencies on a production server is not advisable.
What are the key considerations when deploying a Node.js project on a server?
-Key considerations include ensuring Node.js is installed, configuring any project-related services such as databases, caches, or mail servers, and using tools like PM2 to monitor the project in the production environment.
What is the role of Docker in the deployment process described in the script?
-Docker is used to containerize the project and its dependencies, allowing them to run independently and making it easier to manage starting operations and network configurations for the containers.
What is the purpose of setting up a CI/CD server configuration in the DevOps approach?
-The purpose of setting up a CI/CD server configuration is to automate the process of running integration tests and test coverages before deploying the artifacts to the cloud, ensuring a smooth and error-free deployment.
How does the script suggest handling the database configuration for deployment?
-The script suggests using a cloud MongoDB URL instead of a local database for deployment, which requires configuring the database connection in the project.
What is the significance of setting the port dynamically in the project configuration?
-Setting the port dynamically allows the application to run on the port specified by the environment variable if available, otherwise it defaults to port 8000, providing flexibility for different deployment environments.
What changes are made to the package.json file in preparation for deployment?
-Changes to the package.json file include updating the scripts for building and running the project, specifying the Node.js engine version, and removing unnecessary dependencies and devDependencies.
How does the script handle the creation of orders in the application?
-The script handles the creation of orders by first grabbing the login customer, creating an order ID, grabbing order items from the request, calculating the order amount based on the database information, creating an order with item descriptions, and updating the order in the user account.
What is the next step in the tutorial series after deploying the project on Heroku?
-The next step in the tutorial series is to work on the order section and then transition to a microservices architecture for more advanced development.
Outlines
đ Introduction to Node.js Deployment and DevOps
The speaker begins by welcoming viewers to the channel and announces the continuation of a series on Node.js. They plan to deploy the current progress of their project on Heroku, despite it not being the ideal time, as future episodes will shift towards a microservices architecture. The speaker emphasizes the importance of understanding how Node.js operates in a production environment, highlighting the need for compatibility with ES5 or ES6. They discuss the deployment process, which includes ensuring Node.js is installed on the server, configuring project-related settings, and using tools like PM2 for monitoring. The speaker contrasts the traditional deployment workflow with the DevOps approach, which involves collaboration between development, operations, and quality assurance teams. They touch on Dockerization, Docker Compose for container management, and the use of CI/CD pipelines for automated testing and deployment. The speaker concludes by outlining the steps for deploying on Heroku, including updating the TypeScript configuration and package.json file.
đ ïž Preparing the Project for Heroku Deployment
The speaker continues by detailing the modifications needed for the project to be deployable on Heroku. They start by updating the 'package.json' file to include necessary scripts and dependencies. The speaker removes deprecated packages and adds engines to specify the compatible Node.js version. They also discuss the importance of handling MongoDB errors and making the project compatible with ES6. The speaker demonstrates how to install dependencies and troubleshoot common issues, such as those related to MongoDB. They show how to configure the database connection to use a cloud MongoDB URL and modify the 'index.ts' file to dynamically assign the server port. The speaker concludes this section by committing the changes and demonstrating the creation of an app on Heroku, followed by a successful build and deployment.
đ Deploying and Testing the Application on Heroku
After successfully deploying the application on Heroku, the speaker checks if the app is running correctly by accessing it through a provided URL. They demonstrate how to use Postman to test the application's endpoints, such as creating a vendor and logging in as a banner. The speaker shows how to access logs from the Heroku server to monitor the application's performance. They also discuss the process of making changes to the application and redeploying it on Heroku, emphasizing the ease of updates and the automatic build process. The speaker then shifts focus to the next steps, which include working on the order section of the application and setting up the necessary routes and controllers.
đ Developing the Order Section and Database Interaction
The speaker delves into the development of the order section, starting with the creation of order-related routes and controllers. They discuss the process of handling order creation, including fetching the logged-in customer, generating an order ID, and calculating the order amount based on item details from the request. The speaker emphasizes the importance of using accurate price information from the database to ensure correct order calculations. They demonstrate how to create a data model for orders and modify the customer model to include an orders array. The speaker also shows how to handle the creation of orders, including updating the user's order information and returning the current order details upon successful creation.
đ Implementing Get Orders and Order by ID Functionality
The speaker continues the development of the order section by implementing the functionality to retrieve orders and view a specific order by its ID. They show how to fetch the current customer's orders and use the 'get' method to access the orders array. The speaker also demonstrates how to populate the food details for each order item. They discuss the process of retrieving a specific order by its ID, including populating the food information for that order. The speaker tests these functionalities using a tool like Postman, showcasing the successful retrieval of order details. They conclude by summarizing the progress made in the episode and teasing the upcoming focus on microservices architecture in future episodes.
Mindmap
Keywords
đĄHeroku
đĄMicroservices Architecture
đĄDevOps
đĄDockerization
đĄDocker Compose
đĄCI/CD
đĄTypeScript
đĄES5/ES6
đĄPM2
đĄMongoDB
đĄOrder Management
Highlights
Introduction to the deployment process of a Node.js project on Heroku, transitioning from a monolithic architecture to microservices.
Explanation of the importance of compiling a Node.js project to ES5 or ES6 before deployment, especially when using TypeScript.
Overview of the DevOps approach, emphasizing the automation of development, operations, and quality assurance processes.
Discussion on the necessity of Dockerizing projects and dependencies for efficient deployment and management.
Step-by-step guide on setting up Docker Compose for managing containers and services within a Docker network.
Details on configuring Nginx as a reverse proxy and load balancer for Docker containers.
Instructions on setting up CI/CD server configurations for automatic deployment, testing, and integration.
Demonstration of deploying a Node.js project on Heroku and the importance of post-install scripts for smooth deployment.
Modifications to the TypeScript configuration file, including setting up source and distribution directories.
Instructions for configuring a database connection, transitioning from a local database to a cloud MongoDB instance.
Detailed steps for handling environment variables and setting up dynamic port configurations for deployment.
Explanation of setting up and modifying the package.json file, including managing dependencies and scripts.
Guidelines on creating and managing orders within the application, including creating routes and controllers for order processing.
Instructions on creating a Data Transfer Object (DTO) for order inputs and managing cart items during order creation.
Final demonstration of deploying changes to Heroku, validating successful deployment, and verifying the applicationâs functionality using Postman.
Transcripts
hey there welcome to my channel let's
continue with our series today we will
work on the order section
but right before moving forward we will
deploy our current progress on heroku
i know this is not right time to deploy
our project but
from the next episode onward we will
completely move to microservices
architecture
if people not willing to follow that
architecture so at least
they can continue with the current flow
to publish the final project on
monolithic way
let's understand how the node project is
working on the production environment
first of all we need to build our node
project compatible to es5 or es6
if we're writing on the typescript then
only we will move to the compile output
to the production server
because it is not a good idea to run the
project on the production server
with the typescript directly with the
development dependency right
there are many ways you can deploy your
artifacts on the cloud it depends on
your working style and what kind of
process you are following
in my case i am following devops culture
and i will try to give an overview
then how the things are working in the
devops and the normal flow
in the normal flow usually we are
deploying our project on any web server
or where a couple of things we need to
take care of number one make sure you
have installed node.js in your server
make sure all the pdp sets configured on
your server related to project
example db a cache or mail server etc
and finally we need to install uh pm2 or
similar tools to monitor our projects on
the production environment
if it crashed on runtime so or something
happen
unwanted then it will restart your
project immediately and next upload your
project and start on the specified port
and finally we need to set up a reverse
proxy to bind our expose port
to reach to the audience so that this is
the normal workflow
in the devops way it's a combination of
development operation and the quality
students working together on
sync to sip the final product to the
audience i will not go deeper to make
you understand what devops it is
uh so there are tons of resources
available on the web which can help you
to understand
in this way first we need to dockerize
our project and dependency images
example if you are using mongodb or
mysql
or redis or revit mq for messaging queue
um
so all those things you need to
dockerize first so it can run
independently to perform
starting operations next configure
docker compose file to run the
containers easily through a command
or where the containers reach to the
services together in the same docker
network
next we need to add the engine x to
handle the reverse proxy
for reaching out the exposed port
finally we need to set up the ci cd
server configuration to run our
integration and test coverages
right before deploying our artifacts on
the cloud for example elastic bin stock
or aws instance or maybe google cloud or
digital
etc additionally we can manage our
containers by adding kubernetes and
ingress
engine x is gonna be work as a proxy and
a loop balancer for our containers
so these are some of the advanced topic
definitely we will cover in sunday
so in the in the devops way all the
process are running automatically
when we push a new changes to the master
repository now i hope you got an idea
how we can proceed with the deployment
stage of the node project now let's
deploy this thing in heroku first
and after that we will work on the order
section so here is our project
so far we have covered pretty much good
amount of functionality we will work a
bit on our ts config file here
i am going to wipe it out first all
those things like
here okay
these are the things at least we should
have to be present in our ts config file
so here root directory we are just
pointing to a directory which is going
to be like in a source directory which
is we have not created at all
so let's create that directory um src
and secondly uh the distribution
directory we don't need to create at all
so it will be created automatically
by by typescript when we compile our
source code
i'm going to delete this node module
here okay and
now now let's let's move all those
things to inside the source directory
now now all the files are inside the
source directory good
package log session file we are going to
delete this one
and now we need to do a little bit work
on the package.json file
okay so uh with the help of the tsc
that's p
and dot dot um this this common one when
will we
run this script then it will compile our
whole project by
typescript okay
next next uh right after making the bill
uh we need to add some more things that
is gonna be like post
post install and that will be npm
run though good
so this post install install will be
required as far as hero currently
for other stuff if you are um if you are
deploying on
the docker containers and this is not
going to be necessary at all
all right so um this section is done now
let's come to the dependencies
right before adding dependency we will
add one more thing that is that will be
our engines
here and right right before the
dependency i'm going to add one more
dependency that is kind of a depth
dependencies
and inside the dev defense a couple of
things we will be uh moving from here
so certainly we have everything is clear
here
this body pressure will be not required
because this is deprecated this is
coming inside the
express module right now and this comma
we need to remove all right
so our uh our package.json pilot so it's
totally ready
right let's go to the index.ts file here
go to app
here this body pressure will be not
needed
so we'll be removing this body pressure
here um
it will come as express
the objection and instead of body
pressure i'll just
put x-rays
[Music]
good now the modification of the package
digestion file is done
so uh what what is going to be happening
when we run the dev script then it will
run the
index.ts file inside the source
directory here the directory is missing
that's rc once you run the build script
then the
typescript will be compiled the whole
source code and it will store inside the
distribution directory so we can start
our project uh um the compile source
code
by pointing to this script like npm
start
right all right so right after install
the dependency then the
the this script will be automatically
run so what
it will do like it will it will build it
will run it this build script
right so let's let's install the
dependency mpm
install
okay so our installation is done but the
compile is
is filled because of this uh related to
mongodb error
right so what we are going to do uh it's
a common error so
i'm going to remove these things the
type declaration file
from here i'm going to install ibm
install
yes now it is all it is successfully
installed
let's delete this file delete this
directory first
we will run the this build script and
npm run
[Music]
yeah that's good successfully we have we
have successfully now uh
built our project let's give a try to
run this project
npm
yeah this is perfectly fine now it is
our our js version is
running all right so which is we have
kept which is we have changed
as a targeted version of es6 node
support the es6 version
that's good so um the
basic things are done now what we need
to do we need to configure our
database file here because we are
pointing this database file to our local
repository local database
so i'm going to just comment these
things first here i'll be using cloud
mongodb url
so let's create an account here
is
all right so this is our database
connection is done here uh go to
index.ts file here instead of this port
we will be adding something like in the
configuration file
right here in configuration file
will be export launched
put will be process dot
environment dot port if
a port is available on that the
environment then it will come over here
otherwise we will be listening to the
default 8000 port
right so this is we need to do
next now just to go to the index.ts file
here uh
instead of this port we will be adding
rd port
and now um we'll be
we'll be adding these things to inside
the backtick so at least we can
we can determine like what port it is
running okay
good now this is done um
since everything is perfectly fine all
database configuration also done
good now we will commit all these
changes whatever we have made right here
and now let's create an app on huroku
then this will be
morocco first of all let's check it out
like if i am logging or not
and now let's create an app
real cool create create
app is creating yeah this is my happy
world
so what i'm going to do i'm going to
push all these changes to heroku
yeah that's a good sign our build is
success now the application is available
on this for
this url uh now we have deployed
successfully our our source code on the
horoko
now it is available on this this url
also so it is simply saying
it cannot get all right that's perfectly
fine let's give a try these things from
our postman
sent here have you seen
this is the response from the the server
right
so we are successfully able to create
the uh the vendor so let's
try to try to log in as a banner here
right so login
so as you can see now our application is
running on the huroku
i hope this is going to be helpful
helpful for you so you can get the logs
from here for getting log you need to
use oracle locks that's the stale
right so you can get the whole bunch of
the the locks whatever it is happening
in the server
all right so and now it is perfectly
working fine from our heroku server
and so if suppose something is going to
be changed let's say we are going to
change something here
uh listening to port on
heroku heroku server
[Music]
if there's something exchanged or again
you need to do publish then just
simply do one thing get at
yeah now it will go through the whole
process as we have as we have edit right
here
and finally once this is done then it
will it will start the server
this piece of code will be gonna be
execute where we can see the
up and running server it will be
available for us let's go
yeah this is done now again check the
locks from the hiroko here
and then you will see like if this new
changes has been done definitely will be
it will be look for
listening to report uh on heroku server
the port number as you can see listening
to port on your request server and
port number is 55 868.
uh that's good that's a good time so
let's let's get back to our source code
then we are what we are going to do
we are going to change our our database
url first
because we need to work on the work on
the order section
let's continue with our our progress so
we'll be working on the
the customer route here we'll be
handling our orders first right so let's
move our order below payment
here we'll be adding a couple of routes
for order
um in the controller uh customer
controller
go below here here we'll be creating
so add these things here that will be
our
create order and
here get orders get orders
and here it will be
[Music]
get ordered by id right so it's hooked
up properly
now we'll be adding some code on the
create order here in this section
to create an order we need to grab the
login customer first after that we will
create an order id
and then we will be uh grab the order
items from the request that you
requested
mostly the request will be something
like the id
it will become with id and unit right
and after that we will be calculating
the order amount as per
the available uh as party information
available on the database
then we will be creating an order with
the item description and finally
we will update the order to the user
account and giving the response back
all right so these are the things we
need to do so let's uh let's dive into
to get the get these tapes one by one
somehow we need to grab the request body
as a card and then
but the card is kind of like it will be
kind of array
it's just similar to something like this
okay
so that is we need to do so for that
thing what we will do here
we are we are going to create a dto file
inside the dto here
so it will be technically it's a kind of
like um order inputs
right so all the orders we will grab
right here
now next what you need to do or we will
be adding such a kind of
array that's gonna be like card item
card items and it will be array
all right and net amount will be
will be zero zero zero point zero zero
now we need to calculate the amount here
right so it is giving it is giving us a
bunch of food so whatever available here
whatever request that
whatever we have requested on the card
array then all foods are available here
along with the
the information additional information
that means uh we are having a price in
permission also
here okay which is we have not
considered from the request
the price parameter considering from the
request uh this is not a good idea
if suppose uh instead of the actual
price
if someone is sending some different
price then the whole calculation will be
will be terribly wrong so
now what you'll do here we will be
comparing the specific food id
with the request id if they bought the
id is matching then we will be
calculating the
the total amount depends on the unit of
the specific price
so let's do these things
so to create order we don't have a data
model so that is we need to create here
we're going to the model and we'll be
creating order
ts here i'm going to
do a little bit quicker from just a copy
distance from here
then copy all those things paste it here
and this is gonna be like our order dogs
it
okay
is
so we need to modify our customer model
also here
right so here in the customer model we
will have some additional information
that is going to be like you know we
will have
some orders also here and definitely
it it will be kind of array and it will
represent the order model
good so it's saying your orders
redeclare where we're using
okay that's not an issue in the customer
controller we need to
add a couple of things here that is
by default we need to provide orders
orders initially we will
we will just put in an empty array
good all right here
in the create order um
so once we have created order
successfully whether our current order
has some value or not
if it is not a possible then definitely
we will be
update our user here
hello
good so let's let's have a try with the
creating order
send a request yeah that's good so have
you seen
here we are getting the response right
so this is our order id
this is our order id and these are the
items are available
right this is one first item which is we
have sand unit tree
and this is our second item which is uh
unit one and total amount is the
560 and order date is this
and pedro is the cod and
yeah we do have a pretty much good
amount of information right
when you place the order then these are
the information it is not required this
is unnecessarily
i mean it's it is getting back on server
right so what we will do here
uh will be right after placing the order
um here
[Music]
this uh this profile response will have
some data
that is gonna be like orders yeah simply
this is this is we will return
now again i'm going to create one order
and this time
let's say one items
per okay send yeah
but again this is not meaningful all
right so this is giving
some data but only the ids so what do
you will do here
instead of returning the profile
response order that only you will return
this
current order only okay this one
the current order which is you're
creating in here
and definitely this is not required at
all only we will be calling
save if it is saved successfully then it
will return the current order
now now let's try once once more this
time i'm going to order
two item two units uh each now sandy
permission yeah now it is meaningfully
bit right
it's only this specific ordering
permission is available here
that's good so create order is done now
now we will be work on the get orders
get order is nothing nothing special so
what we need to do
uh this is the same thing we we will be
doing here
first uh grab the current current
customer
let's go to check the getters
functionality also here in customer role
we are using orders
it's a get call
yeah that's good all right so we have
the three orders available here
and next we need to take care of the
order by id
so this functionality also will be
pretty much the same
here in in the order in the order model
we have
we have items specific items array also
have a food
so we are just populating the food also
from here by
assigning this way populate items dot
food
so once you are grabbing that specific
order information then we are returning
back to the client
let's have a try with the get order by
id functionality also here
all right so we are grabbing we will be
we will grab this already copy
and view order by id
here we will be use this already wow
great
have you seen here we are getting all
the informations available for that
specific order
so this is our order id and these are
the items that
exist inside the order now our order
section also clear
in the upcoming episode we will be
working on a microservices architecture
where we will be splitting up our
modules to microservices
so a lot of advanced stuff we need to do
right there so
see you in the next episode and happy
new year
Voir Plus de Vidéos Connexes
Day-19 | Jenkins ZERO to HERO | 3 Projects Live |Docker Agent |Interview Questions | #k8s #gitops
What is DevOps? Understanding DevOps terms and Tools
you need to learn Docker RIGHT NOW!! // Docker Containers 101
DevOps Interview For Experience : First Round Selected
Full Node.js Deployment - NGINX, SSL With Lets Encrypt
Install Flowable with Docker | How-To | Flowable
5.0 / 5 (0 votes)