DEV Community

Cover image for Getting Started With Nest.js
Shameel Uddin
Shameel Uddin

Posted on

17 4 3 3 3

Getting Started With Nest.js

Introduction

Hello everyone, we are starting a series where we will be learning about Nest.js as a framework, understanding fundamental concepts and getting down to its depth.

Please find video explanation below ↓

Node.js -> Express.js -> Nest.js

Lets discover how we arrived at nest.js.

By no means, after the arrival of nest.js, does node.js or express.js become obsolete.

Node.js in itself can be used in variety of applications like scripting, automation and stuff and Express.js is also being utilized in industry, on top of which great applications have been built and are currently in use.

Node.js

Initially, JavaScript used to execute only in Web Browser.

Node.js came with a BANG and allowed JS to be written and executed at server side.

Note: It's not a library or framework of JS but it's a RUNTIME ENVIRONMENT!

However, in node.js, we had to write a lot of code for a server to make simple CRUD applications.

Thus, came: Express.js

Express.js

It is an unopinionated, minimalist framework based on node.js

It solved extra over-code which we used to do it in node.js but it is unopinionated which means anyone can use its own type of structure of however he wishes it to be. It does not provide any sort of strictness. Anyone can do whatever they want to do with it and however they want to do with it. No any design pattern is enforced. Just do as you like.

Nest.js

Nest.js uses Express.js as underlying technology which is built on top of Node.js.

It provides a proper structure to do stuff, implying design patterns, and a proper way in modular usage for Controllers and Services. You have to follow a standard to make things work. So, if someone has a knowledge of nest.js.

PS. Nest.js also allows you to use Fastify as underlying tech if you don't want to use express.js.

Problems Tackled

Each of these solved their own problems. Node.js allowed JS to be written on server. Express.js removed extra code and allowed ease in development and Nest.js restricted developers to use good coding practices.

Prerequisite

You should have knowledge of the following before moving forward to the Nest.js series:

  • JavaScript
  • TypeScript
  • Node.js
  • Client-Server Architecture
  • Express.js (Somewhat)

Installing Nest.js

You should have node.js installed. You can verify it with running this in CMD:

node -v
Enter fullscreen mode Exit fullscreen mode

Open Command Prompt in Administrative mode and run this:

npm i -g @nestjs/cli
Enter fullscreen mode Exit fullscreen mode

This will install nest.js globally in your system.

Creating Nest.js Project

After that you can create project with this:

nest new <project-name>
Enter fullscreen mode Exit fullscreen mode

For myself, I could do it like this:

nest new shameel-project
Enter fullscreen mode Exit fullscreen mode

You will be provided with these three package managers:

  • npm
  • yarn
  • pnpm

I chose npm and moved forward.

Wait for a while and then Nest.js project will be created.

What's Next?

We will be discovering and understanding the file structure and what the file means which have been created by default from executing above command.

Stay tuned! =)

Follow me for more such content:
YouTube: https://www.youtube.com/@ShameelUddin123
LinkedIn: https://www.linkedin.com/in/shameeluddin/
Github: https://github.com/Shameel123

Top comments (1)

Collapse
 
mobisoftinfotech profile image
mobisoftinfotech

Great introduction to NestJS and its evolution from Node.js and Express.js! The structured approach and setup guide are super helpful.

For those exploring event-driven architecture, integrating AWS SQS and SNS with NestJS enhances asynchronous messaging. i fund this page: mobisoftinfotech.com/resources/blo... for a hands-on TypeScript AWS integration guide.

Its great to read your throghts about Have you tried implementing AWS SQS with NestJS? Would love to hear your experience!

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay