プロジェクト構成とCLI
CLIを使って新しいNestJSプロジェクトを初期化し、デフォルトのフォルダー構成を理解して、コンポーネントを効率的に生成します。
「プロジェクト構成とCLI」はCoddyKit上の無料NestJS Enterprise Backend APIsレッスンです。 これはレッスン2/3です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはNestJS Enterprise Backend APIs学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 NestJS Enterprise Backend APIsコースには全3レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「プロジェクト構成とCLI」レッスンは無料ですか?
はい。「プロジェクト構成とCLI」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NestJS Enterprise Backend APIsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NestJS Enterprise Backend APIsコースには全3レッスンが含まれています。
「プロジェクト構成とCLI」で何を学びますか?
CLIを使って新しいNestJSプロジェクトを初期化し、デフォルトのフォルダー構成を理解して、コンポーネントを効率的に生成します。 ブラウザで直接実行するハンズオンコードでNestJS Enterprise Backend APIsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
NestJS Enterprise Backend APIsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNestJS Enterprise Backend APIsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/3です。
「プロジェクト構成とCLI」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNestJS Enterprise Backend APIsレッスンでコードを書いて実行できますか?
はい。すべてのNestJS Enterprise Backend APIsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- NestJSフレームワーク入門
- プロジェクト構成とCLI
- モジュール、コントローラー、サービス