Nestjs backend rest api - Ecommerce project. Introduction & setup.

bilchalan
26 Apr 202308:14

Summary

TLDRThis video tutorial guides viewers through creating a backend REST API for an e-commerce project using Nest.js, a framework for Node.js applications. It highlights the choice of TypeScript for type safety and TypeORM for database interactions with PostgreSQL. The presenter demonstrates installing necessary software, setting up the project structure with npm, and configuring the initial server to run on port 3000. The script also briefly touches on dependency injection and service creation, providing a foundational step for building out the API.

Takeaways

  • πŸ› οΈ The speaker is creating a back-end REST API using the Miss.js framework for Node.js server-side applications.
  • πŸ“š TypeScript is chosen alongside Miss.js for its strong typing features, enhancing code quality and maintainability.
  • πŸ” The ORM (Object-Relational Mapping) tool of choice is TypeORM, facilitating database interactions in a more abstract way.
  • πŸ—ƒοΈ PostgreSQL is selected as the database for its robustness and scalability, suitable for an e-commerce platform.
  • πŸ›’ The project is an e-commerce REST API, chosen for its comprehensive coverage of major features without being overly complex.
  • πŸ’» Software prerequisites include Node.js, PostgreSQL, and a code editor like VS Code.
  • πŸ”§ Postman or similar tools are recommended for checking API routes and functionality.
  • πŸ“ The script provides step-by-step instructions for setting up the project, starting with installing Miss.js CLI.
  • πŸ“ The project structure includes essential files like main.ts, app.module.ts, and app.controller.ts for organizing the application logic.
  • πŸ”„ Dependency Injection is mentioned as a concept that will be explored later in the context of Miss.js services.
  • πŸ”— The script outlines how services and controllers interact within the Miss.js framework, with services providing business logic and controllers handling requests.
  • πŸš€ The final takeaway is about configuring the database connection, which is crucial for the API to interact with the PostgreSQL database.

Q & A

  • What is the purpose of creating a back-end REST API using Miss.js?

    -The purpose is to create an e-commerce REST API, which is chosen for its comprehensive coverage of major features suitable for a medium-sized project.

  • Why is Dash JS chosen for the Node.js server-side application?

    -Dash JS is chosen because it is a framework that is typically used for creating server-side applications in Node.js.

  • What is the role of TypeScript in this project?

    -TypeScript is used alongside Miss.js to provide type safety and other benefits of static typing in the development of the e-commerce REST API.

  • What ORM is being used in conjunction with TypeScript?

    -TypeORM is being used as an Object-Relational Mapping (ORM) tool alongside TypeScript to interact with the database.

  • Which database is chosen for the e-commerce REST API project?

    -PostgreSQL is chosen as the database for the project due to its robustness and scalability.

  • What software is required to be installed before starting the project?

    -Node.js, PostgreSQL, and an IDE like Visual Studio Code are required to be installed before starting the project.

  • What is the role of Postman in the development process?

    -Postman is used for checking and testing the routes of the REST API during the development process.

  • How does one initiate the creation of a new application using Miss.js CLI?

    -One initiates the creation of a new application by running the command 'npm init @miss-js/cli' followed by 'next <project-name>', such as 'next Bazaar API'.

  • What is the significance of the 'main.ts' file in the project structure?

    -The 'main.ts' file is the entry point of the application, where the server is set up to run on a specific port and the app module is initialized.

  • What is the function of 'app.module.ts' in the application?

    -'app.module.ts' is responsible for importing other modules, controllers, and providers that are part of the application's architecture.

  • Why is 'app.controller.speak.ts' being deleted from the project?

    -'app.controller.speak.ts' is intended for unit testing, which is not part of the current project scope, hence it is being deleted.

  • What is the role of dependency injection in the application?

    -Dependency injection is used to manage the dependencies of the application, such as services, in a way that promotes modularity and ease of testing.

  • How is the 'app.service.ts' utilized in the application?

    -'app.service.ts' defines the services used in the application, which can be injected into controllers to provide business logic or data access.

  • What does the 'app.controller.ts' file contain?

    -'app.controller.ts' contains the controllers that handle incoming requests and interact with services to return responses.

  • How does the application configure the database connection?

    -The script does not provide explicit details on configuring the database connection, but it is implied that this will be covered in subsequent steps of the project.

Outlines

00:00

πŸ› οΈ Setting Up a Back-End E-Commerce REST API with Miss.js

The speaker introduces the project of creating a back-end REST API for an e-commerce platform using Miss.js, a framework for Node.js server-side applications. They chose this project for its comprehensive coverage of major features without being overly complex. The video script details the installation of necessary software, including Node.js and PostgreSQL, and the use of VS Code for coding. It also covers the use of Postman for route checking. The process begins with installing 'next-js-cli' using npm and creating a new project named 'Bazaar API'. The script explains the file and folder structure generated by the 'next' command, including the main entry point in 'main.ts' and the server's configuration to run on port 3000.

05:01

πŸ“‚ Exploring the Project Structure and Initial Setup

This paragraph delves into the project's source (SRC) folder, which contains several files crucial for the application's operation. The speaker explains the purpose of each file, such as 'main.ts' being the entry point, 'app.module.ts' for importing modules, controllers, and providers, and 'app.controller.ts' for creating controllers. The script mentions the deletion of the 'app.controller.speak.ts' file as it's for unit testing, which is not part of the current project scope. It also touches on the concept of dependency injection through 'app.service.ts', which is the only service file and is injectable, returning a 'hello world' string when called in the controller. The paragraph concludes with a mention of configuring the database connection in subsequent parts of the video.

Mindmap

Keywords

πŸ’‘REST API

REST API stands for Representational State Transfer Application Programming Interface. It is an architectural style for designing networked applications. In the context of the video, the creator is building a back-end REST API for an e-commerce application using the Nest.js framework, which allows for the development of scalable server-side logic.

πŸ’‘Nest.js

Nest.js is a JavaScript framework for building efficient, reliable, and scalable server-side applications. It uses TypeScript and is particularly well-suited for creating REST APIs. In the script, the speaker has chosen Nest.js for its robust features and its ability to handle complex e-commerce functionalities.

πŸ’‘TypeScript

TypeScript is a statically typed superset of JavaScript that adds optional types to the language. It is used to improve the maintainability and scalability of JavaScript applications. The speaker mentions using TypeScript alongside Nest.js, highlighting its importance in the development process for type safety and developer productivity.

πŸ’‘ORM

ORM stands for Object-Relational Mapping. It is a programming technique for converting data between the object model representation and the relational database representation. The speaker mentions using TypeORM, a specific ORM, to interact with the PostgreSQL database in their e-commerce API.

πŸ’‘PostgreSQL

PostgreSQL is a powerful, open-source object-relational database system with an emphasis on extensibility and standards compliance. It is chosen by the speaker for its robustness and rich feature set, suitable for handling the data storage needs of an e-commerce application.

πŸ’‘E-commerce

E-commerce refers to the buying and selling of goods or services using the internet, as well as the transfer of money and data to execute these transactions. The speaker chose an e-commerce project because it encompasses a wide range of features, providing a comprehensive scope for demonstrating the capabilities of the API being developed.

πŸ’‘VS Code

VS Code, or Visual Studio Code, is a popular source code editor developed by Microsoft. It is known for its rich ecosystem of extensions and support for a variety of programming languages. The speaker mentions using VS Code for coding, which is a common choice among developers due to its powerful editing capabilities.

πŸ’‘Postman

Postman is a collaboration platform for API development that helps developers design, build, test, and document APIs. In the script, Postman is mentioned as the tool the speaker will use to check the routes of the API, demonstrating its importance in the API development lifecycle.

πŸ’‘npm

npm stands for Node Package Manager and is a package manager for JavaScript, used for installing and managing packages for Node.js applications. The speaker uses npm to install Nest.js CLI, which is essential for creating and managing the e-commerce API project.

πŸ’‘Dependency Injection

Dependency Injection is a design pattern used to implement Inversion of Control (IoC) for the resolution of dependencies. It allows for more modular and testable code by reducing the coupling between classes. The speaker briefly mentions this concept in the context of the AppService being 'injectable' in the Nest.js application.

πŸ’‘Controllers and Services

In the context of an MVC (Model-View-Controller) architecture, which Nest.js follows, controllers handle the incoming requests and use services to perform business logic. The speaker refers to 'app.controller.ts' for handling requests and 'app.service.ts' for the service layer, illustrating the separation of concerns in the application structure.

Highlights

Creating a back-end REST API using Nest.js, a framework for Node.js server-side applications.

Utilizing TypeScript along with TypeORM as an ORM for database interactions.

Choosing PostgreSQL as the database for the e-commerce REST API.

E-commerce project selected for covering major features without being too large or small.

Installing necessary software like Node.js and PostgreSQL before starting the project.

Using Visual Studio Code as the preferred code editor.

Checking routes with Postman or alternative tools like Insomnia.

Installing NestJS CLI using npm for project scaffolding.

Creating a new project folder and initializing it with NestJS CLI.

Choosing npm as the package manager for the project.

Exploring the file structure generated by NestJS, including node_modules, src, and package.json.

Deleting unnecessary test files to focus on the main application logic.

Understanding the role of main.ts as the entry point of the application.

Importing AppModule and setting up the server to run on port 3000.

AppModule's responsibility to import files, controllers, and providers.

Introduction to dependency injection and its usage in the application.

Creating and organizing controllers and services within the application.

Using AppService for business logic and injecting it into the controller.

Configuring the database connection for the e-commerce REST API.

Transcripts

play00:06

delete your welcome

play00:11

I am going to create a back-end rest API

play00:14

with miss.js

play00:16

Dash JS is used for node.js server side

play00:19

application

play00:22

it's a framework I choose to create an

play00:25

e-commerce rest API

play00:27

's framework typically use

play00:30

typescript I also

play00:32

use typescript along with

play00:35

type or M as an orm and as for database

play00:40

I use postgres SQL

play00:44

you can ask why I choose eCommerce

play00:46

project

play00:47

I chose it because it's not a small

play00:49

project

play00:51

but not the biggest project either

play00:53

actually it's covered most of the major

play00:56

features that I know

play01:00

before going to create these

play01:03

rest API we need to

play01:05

install some softwares

play01:09

first is node.js

play01:12

then

play01:16

database postgres SQL

play01:19

I am

play01:20

using vs code

play01:23

for coding you can use vs code or

play01:25

whatever you want

play01:27

and

play01:29

checking the route

play01:31

I will use

play01:34

Postman you can use Postman or insomnia

play01:36

or whatever you compute till compute

play01:40

okay

play01:42

if you

play01:43

install these

play01:45

softwares then here

play01:49

these

play01:51

messages documentation

play01:55

it says several

play01:58

points to

play02:01

install niches

play02:05

there is another one

play02:08

there is another one but I

play02:11

I will use this

play02:14

npm I

play02:16

Dash G at Ms JS slash CLI then next new

play02:23

then project name

play02:25

so

play02:26

I'm copying these

play02:29

line first npm I Dash G at mesh JS CLI

play02:36

I have opened my visual studio code

play02:40

then I open my terminal

play02:44

so

play02:46

I create a next API namely

play02:49

a folder and it's in desktop

play02:54

you can choose

play02:56

file path or folder path and your viewer

play02:59

computer

play03:00

now I am

play03:03

paste this line and click on enter

play03:08

it will

play03:10

take some time

play03:15

okay I have installed next jscli now

play03:18

it's time to create new application

play03:21

openness.js

play03:22

to

play03:23

install new application we have to

play03:27

copy these

play03:29

command

play03:30

then go again

play03:33

paste it next new project name and I am

play03:37

going to

play03:40

name it

play03:42

Bazaar API

play03:45

okay next new Bazar API without

play03:53

installing this next jsli remember it

play03:57

will not

play03:58

what so first install this JS CLI then

play04:03

this command will work

play04:07

next it tells which package manager

play04:11

audio

play04:12

like to use I am using npm if you

play04:16

want you can choose yarn or pnpm I'm

play04:19

using npm enter

play04:25

okay

play04:29

it's installed

play04:31

now if we expand

play04:35

API folder we can see the

play04:39

node.js messages

play04:42

file and folder structure plus node

play04:44

modules then SRC test then sum of the

play04:49

file

play04:50

we

play04:52

should have used

play04:54

package.json

play04:57

there is

play04:59

starting

play05:00

script

play05:02

third div

play05:05

and Etc

play05:08

let's open SRC folder

play05:12

SRC folder has some several files

play05:15

main.ts appservice.ts

play05:19

app

play05:20

Dot module.ts

play05:23

app.controller.ts

play05:24

app.controller.speak.ts

play05:28

this speak dot TS this is for unit

play05:31

testing we are not going to paste

play05:33

anything or dot unit testing

play05:37

so I am going to

play05:39

delete this file first because we don't

play05:42

I don't need this

play05:47

okay

play05:48

main.ts this is our entry

play05:51

point

play05:52

and this import next Factory import app

play05:55

module

play05:57

this is the boot step

play05:58

this function will be called first

play06:01

and here is our

play06:04

server is running on Port 300. and it's

play06:09

have it list Factory dot create app

play06:11

module and where is our app module app

play06:14

module is app.module.ts

play06:17

so this file

play06:19

call in Main

play06:21

dot TS and app module it's can import

play06:26

file

play06:28

and controller and providers

play06:31

there is only one controller

play06:33

app controller and here is our app

play06:36

controller this is this

play06:39

you can create as many as you want

play06:43

and then you have to

play06:47

put this

play06:49

their controllers after one controller

play06:52

then comma another controller and

play06:54

providers providers is Services Services

play06:57

there is only one service in this app so

play07:01

for now this is

play07:03

app.service.ts this is app service and

play07:07

it's injectable what is

play07:09

dependency injection we will see it

play07:12

later but first It

play07:16

app service and it return date hello

play07:19

which string hello world and it's called

play07:21

in controller

play07:23

if you open controller app controller

play07:27

here is the gate hello string and this

play07:30

is called these dot f service dot gate

play07:32

hello these dot app service and if this

play07:34

is our

play07:36

service and it's called this function so

play07:40

it will return hello world and it will

play07:43

return hello

play07:45

and this is string

play07:48

so

play07:49

this is for now next oh you will

play07:54

see how to

play07:56

configure our database connection

play08:00

okay bye

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
REST APINode.jsTypeScriptDash.jsMiss.jsE-commerceBackendPostgreSQLVS CodePostmanNPM