Another JS Framework, Another Day!
The novelty; and truly a differentiator for this framework is – It attempts to solve a ubiquitous problem of application development in Node.js runtime; namely architecture of application!
Best place to get familiar with a framework is the documentation provided by the framework developer themselves. There might be few frameworks which missed big time on such docs but then you have their githuburl’s :). Fortunately for Nest we have a good documentation and I would rather say amazing documentation.
For a developer who is consuming a new framework a major hurdle is to find the right purpose and place to put the framework in use. Documentation from the authoring developer; though a good place to start is sometimes is loaded with adjectives which are difficult to translate to purpose or scenario to put it to use. In the case of Nest these adjectives are(ii)
If you care reading further in the philosophy section of the documentation you would notice these additional adjectives all in the same sentence(ii) –
- Highly testable
- Scalable (again)
- Loosely coupled
- Easily maintainable
These adjectives though seem to delude us from the purpose but help set expectations the quality attributes (scalable solution, developer efficiency, ease of maintenance, test-ability) of the solution we build.
These are the official packages available by the framework collaborator / author at the time of writing this article –
- @nestjs/common – Most used package of Nest. It offers fundamental blocks of Nest which are further extended in the core package. Refer the package.json in core to understand their relationship.
- @nestjs/core – Offers much of the strength to the framework. You will mostly consume the types here and if you intend to indulge; you can extend Nest from the types defined here.
- @nestjs/websockets – Offers the functionality of websocket and observablesocket.
- @nestjs/microservices – Offers the basic infrastructure with plumbing required to implement microservices in Nest.
- @nestjs/passport – Offered as a recipe which uses the Passport strategy to authenticate in Node.js runtime.
- @nestjs/cqrs, – Offered as a recipe that implements the Command Query Responsibility Segregation design pattern in Nest framework
- @nestjs/swagger – Offered as a recipe which exposes OpenAPI (swagger) features for use within Nest framework.
- @nestjs/typeorm – Offered as technique to connect with databases along with the ORM capabilities.
- @nestjs/graphql – A wrapper module to Apollographql server. This module helps Nest classes consume graphql.
- @nestjs/mongoose – A wrapper module to Mongoose
- @nestjs/elasticsearch – A wrapper module toelasticsearchnpm package.
- @nestjs/ng-universal – A wrapper module for the angular’s universal module.
Evan You best describes the term in the context of complexity here. In the context of Nest; it is best experienced by the diverse packages available which offer bounty of a feature / architectural or design pattern. These packages are modelled as adapters and plugins (two common design patterns). Best experienced by peeking into the package.json file e.g. for @nestjs/corepackage
This is that one aspect we did not introduce ourselves while we were getting to understand the Nest framework. The framework combines
- Object oriented programming – Being developed in TypeScript; it has to be naturally OO
- Functional programming – Framework uses features of Closure, Promises, etc.
- Functional reactive programming – Being built using advanced features of ES standards; framework uses Observable, async-await etc.
Knowledge of though does not contribute towards identifying the purpose but does contribute towards a well-built solution. Oh oops, I stand corrected the application of this (programming paradigm) knowledge contributes towards a well-built solution. By “application of knowledge” I mean the design of the domain / problem statement you intend to solve. Best use of the framework will be by designing the application using the same mix of OO, FP and FRP in different bounded contexts.
Getting the hands dirty
Plethora of content on the internet can help you get started. However, the critical stuff for you to get started are to have the right set of pre-requisites. Here we will do just that; take a look at the right set of pre-requisites.
There could be no better place and authority than package.json of the Nest framework to list the pre-requisite –
“node”: “>= 8.9.0”
This line essentially indicates we will need Node.js version 8.9.0 and higher to use Nest framework. Depending on the operating system your box has you should download and install the Node.js version 8.9.0 or higher. Choose your own style of installation whichever you feel comfortable.
Once you have completed the Node.js installation you can quickly start with Nest but with one constraint – What do you want to do? Typically, the answer will be “Hello World” program. Do not tell me that you came all this way to say “Hello Word” or “Hello Nest” or something like that.
It is highly recommended you surf the samples developed by the author of the framework itself – https://github.com/nestjs/nest/tree/master/sample
Different scenarios different sample. You should also attempt stitching two samples together to build an application of your own choice. The most elegant way to explore the existing sample is to clone the repository to your own box. Consider using git command line to issue the following command
git clone https://github.com/nestjs/nest.git
You could then use a preferred IDE like VS Code or Atom to run and analyse the sample..
The Editorial Board