0Pricing
NestJS Enterprise Backend APIs · Lesson

Project Structure and CLI

Learn to initialize a new NestJS project using the CLI, understand the default folder structure, and generate components efficiently.

Project Structure and CLI is a free NestJS Enterprise Backend APIs lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NestJS Enterprise Backend APIs learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

NestJS CLI: Your Development Ally

The NestJS CLI is your dev assistant — it scaffolds projects, generates boilerplate for modules and services, and runs your builds.

Get the CLI Up and Running

Install the CLI globally with npm i -g @nestjs/cli (Node and npm required first). The -g flag makes the nest command available everywhere.

Starting a New NestJS App

Create a project with nest new my-first-backend. The CLI asks for a package manager, then sets up files, dependencies, and boilerplate.

Understanding the Project Layout

A new project's layout: src/ holds your code, node_modules/ the dependencies, test/ e2e tests, and dist/ the compiled output.

Core Application Files in `src`

Inside src/ are the core files: main.ts bootstraps the app, app.module.ts is the root module, plus a starter controller and service.

`main.ts`: Application Entry Point

main.ts is the entry point: NestFactory.create() builds the app and app.listen() starts the server, usually on port 3000.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
  console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();

Building Blocks: A Simple Class

NestJS runs on classes — controllers, services, and modules are all TypeScript classes. This runnable snippet shows the basic class structure.

class Greeter {
  name: string;

  constructor(name: string) {
    this.name = name;
  }

  greet(): string {
    return `Hello, ${this.name}! Welcome to CoddyKit.`;
  }
}

// This is the entry point for running the example
function main() {
  const greeter = new Greeter("NestJS Learner");
  console.log(greeter.greet());
}

main();

Streamline with `nest generate`

As the app grows, use nest generate (or nest g) to scaffold modules, controllers, services, guards, pipes — and auto-wire them in.

CLI in Action: New Module

For a Users feature, run nest g module users. The CLI creates the folder and users.module.ts, then registers it in your root AppModule.

Test Your CLI Knowledge

You've learned about the NestJS CLI and how it helps set up and structure your project.

Which CLI command is used to quickly create a new NestJS project named my-api?

Summary: CLI & Project Setup

You used the CLI: installed it, created a project with nest new, explored the layout, and scaffolded components with nest generate.

Frequently asked questions

Is the “Project Structure and CLI” lesson free?

Yes — the full text of “Project Structure and CLI” is free to read here on the web, and the NestJS Enterprise Backend APIs course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NestJS Enterprise Backend APIs course, upgrade to CoddyKit PRO.

What will I learn in “Project Structure and CLI”?

Learn to initialize a new NestJS project using the CLI, understand the default folder structure, and generate components efficiently. You practise NestJS Enterprise Backend APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NestJS Enterprise Backend APIs?

No prior experience is required. NestJS Enterprise Backend APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Project Structure and CLI” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NestJS Enterprise Backend APIs lesson?

Yes. Every NestJS Enterprise Backend APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to NestJS Framework
  2. Project Structure and CLI
  3. Modules, Controllers, Services
← Back to NestJS Enterprise Backend APIs