Skip to the workspace
Pebellslearn by building
Introduction to Angular  ›  Capstone Project

Setting Up a New Project

Setting up a New Project 15 minThe Angular CLI creates a ready-to-run project with ng new, serves it with live reload using ng serve, and adds new pieces with ng generate.

angular / Setting Up a New Project

Explore each scene at your own pace.

01 · The rule

The rule

Setting Up a New Project

Greenhouse needs a home on your computer. You could wire up TypeScript, a bundler, a test runner and a dev server by hand, but Angular ships a tool that does all of it in one command. Learn three commands and you can start any Angular project.

The rule

ng new creates, ng serve runs, ng generate adds.

Everything goes through the Angular CLI, a command-line tool installed with npm. You need Node.js first.

npm install -g @angular/cli   # once per computer
ng new greenhouse             # create the project
cd greenhouse
ng serve                      # run it at http://localhost:4200

ng new asks a few questions (such as which stylesheet format to use), creates the folder and installs packages. ng serve compiles the app, serves it locally, and rebuilds and refreshes the browser every time you save.

The files that matter first:

  • src/index.html — the single HTML page; it contains the root tag <app-root>.
  • src/main.ts — the starting point. It calls bootstrapApplication with the root component.
  • src/app/ — your components. The root one is the App class (called AppComponent in older projects).
  • src/app/app.config.ts — app-wide setup such as the router and HTTP client.
  • angular.json and package.json — build settings and dependencies.
// src/main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { App } from './app/app';

bootstrapApplication(App, appConfig);

To add pieces, let the CLI write the boilerplate:

ng generate component plant-card   # short form: ng g c plant-card
ng generate service plant           # short form: ng g s plant
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.