To require other types of data, you need to install other middleware, such as body-parser (express.json() module can be used after Express v4.16), cookie-parser (for logging in/out), cors (Cross-origin resource sharing), etc.
These middlewares need to be studied and used to create the service the developer desires.
The layered architecture pattern is an architecture created from the SRP principle (Single-Responsibility Principle, or 단일 책임 원칙, S from the SOLID principles) from the SOLID principles.
Single-responsibility Principle (SRP) states:
A class should have one and only one reason to change, meaning that a class should have only one job.
-Reference
The layered architecture pattern has the following common characteristics.
🔔 With express, you need to clearly design a directory according to this layered architecture pattern and add more concepts if required by any changes or additions in the service requirements.
This may be fine for a senior developer but may be difficult for a junior developer.
Express is so well-known that there is a CLI tool such as express-generator
or other developers create an open-source boilerplate (boilerplate: sections of code that are repeated in multiple places with little to no variation). However, these boilerplates aren't officially recognized and must be decided to be used by the developer.
Nest.js is a web framework based on Typescript and commands. Because it's based on Typescript, it can strictly check types and avoid various exceptions in advance.
To create a controller named 'Posts' type the following command:
nest g co posts
g
: generate
co
: controller
posts
: name
A big pro of Nest.js is that it can exactly create various components needed for a web servers, such as controllers, service, middlewares, interceptors, etc. Nest.js will systematically create this components, preventing developers from making mistakes. It also automatically creates the project directory.
This helps developers to only focus on creating the key logic for the web server.