Getting Started With Nest.js

Shameel Uddin - Dec 25 '23 - - Dev Community

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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player