This is the first post about NestJS. The introduction
NestJS is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of Object Oriented Programming, Functional Programming, and Functional Reactive Programming.
Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!
Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. This allows developers the freedom to use the myriad of third-party modules which are available for the underlying platform.
Prerequisites
You have to make sure that Node.js (>= 10.13.0) is installed on your operating system.
Language
NestJS is built with and fully supports TypeScript. However, Nest is compatible with both TypeScript and pure JavaScript. This framework takes advantage of the latest language features, so to use it with vanilla JavaScript we need a Babel compiler.
Why NestJS?
The main problem with other javascript frameworks is the structure of the project made with them. The majority of them has many powerful features and solutions but they dont have a easy testeable structure or a heavily convoluted file tree. However, Nest provides an out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications. The architecture is heavily inspired by Angular.
Strengths
[X] Typescript and Javascript fully support
[X] Powerful CLI
[X] Decorators
[X] Extensible, Versatile, Progressive
[X] Open Source
[X] GraphQL Friendly
[X] WebSockets integrated
Powerful CLI
The Nest CLI is a command-line interface tool that helps you to initialize, develop, and maintain your Nest applications. It assists in multiple ways, including scaffolding the project, serving it in development mode, and building and bundling the application for production distribution. It embodies best-practice architectural patterns to encourage well-structured apps.
All nest commands follow the same format:
nest commandOrAlias requiredArg [optionalArg] [options]
Command overview
Platform
Nest aims to be a platform-agnostic framework. Platform independence makes it possible to create reusable logical parts that developers can take advantage of across several different types of applications. Technically, Nest is able to work with any Node HTTP framework once an adapter is created. There are two HTTP platforms supported out-of-the-box: express and fastify. You can choose the one that best suits your needs.
Installation
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications on top of TypeScript & JavaScript (ES6, ES7, ES8) 🚀
A progressive Node.js framework for building efficient and scalable server-side applications.
Description
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Nest makes use of Express, but also, provides compatibility with a wide range of other libraries, like e.g. Fastify, allowing for easy use of the myriad third-party plugins which are available.
Philosophy
In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like Angular, React and Vue which improve developer productivity and enable the construction of fast, testable, extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers and tools…
Install via npm:
npm i -g @nestjs/cli
nest new project-name
Install via yarn:
yarn add @nestjs/cli
nest new project-name
Useful Templates
Made with Docker and Prisma:
Nest.js Backend Template
Getting started
- Clone this repository and open it
$ git clone https://github.com/z1-lab/nestjs-backend-template
$ cd nestjs-backend-template
- Install dependencies
- Create a copy of the
.env.development
file and call it .env
. Update the environment variables to match your current environment.
$ cp .env.development .env
- Launch a PostgreSQL database with docker, it will use the port defined in the
DB_PORT
var.
- Generate the prisma client
- Create the database model
$ yarn prisma migrate up --experimental
- Launch the dev mode
- If you're going to edit the GraphQL schema, run the following command to regenerate the TypeScript types.
$ yarn gql:typings --watch
Scripts
-
yarn dev
. Runs the project in dev mode, which means that it won't check types and will restart with every change you make.
-
yarn build
. Compiles the project to the ./dist
folder.
-
yarn typecheck
…
Typescript nestjs starter:
Nest framework TypeScript starter ☕
Follow me on Twitter if you want to know about my future articles, projects or whatever