2.8 KiB
Modern, powerful web application framework for Node.js.
Description
Nest is a powerful web framework for Node.js, which allows you to easily build efficient, scalable applications. It uses modern JavaScript, is built with TypeScript and bring best concepts to JavaScript back-end world such as Dependency Injection (with IoC Container) and Separation of Concerns.
It is not just another framework. You do not have to wait on large community, because Nest is built with awesome, popular well-known libraries - Express and socket.io! It means, that you could quickly start using framework with no worries about a third party plugins.
Nest is inspired by Spring and Angular and is very much still a work in progress.
Installation
$ npm install nest.js
Quick Start
####app.ts
import { NestApplication } from "nest";
export class Application implements NestApplication {
constructor(private express) {
// some configuration stuff
}
start() {
// do something before server start
this.express.listen(3030, () => {
console.log("Application listen on port:", 3030);
});
}
}
####app.module.ts
import { Module } from "nest";
@Module({})
export class ApplicationModule {}
####server.ts
import { NestRunner } from "nest";
import { ApplicationModule } from "./app.module";
import { Application } from "./app";
NestRunner.run(Application, ApplicationModule);
That's it! As you can see, it is possible to add some code between two 'lifecycle' events of Express instance - after server creation and before server listening (which means after all framework stuff). Why it is important? Cause right now, you could simply put here some necessary configurations, for example setup body-parser middleware or morgan logger.
Setup first controller
Controllers layer is responsible for handling HTTP requests. This is how we create controller in Nest application:
@Controller({ path: "users" })
class UsersController {
@RequestMapping({ path: "/" })
getAllUsers(res, req, next) {
res.status(201).json({});
}
}
