To build a new backend api that you can host in AWS Lambda or Azure app services, you can start with a blank node project. You should just install nest - npm -install nest
When nest is installed, call the cli and it will scaffold a project for you.
npx @nest/cli new project-name
nest will create the src folder for you, it will setup a controller, a module, a test and a service. It will also create main.js and assign port 3000 as your default. You can access the app on port 3000 immediately.
Adding swagger
install swagger from the terminal
npm install --save @nestjs/swagger
in main.js, import swagger
import { DocumentBuilder,SwaggerModule } from '@nestjs/swagger';
Then you setup swagger details using options and then render it to /api using app as a parameter.
const options = new DocumentBuilder()
.setTitle('My API')
.setDescription('My API description')
.setVersion('1.0')
.build();
const document =SwaggerModule.createDocument(app,options);
SwaggerModule.setup('api',app,document);
Top comments (0)