DEV Community

Andre Carstens
Andre Carstens

Posted on

1

Create npm api project with nest

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);

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️