Installing the Angular CLI
Install the Angular CLI once with npm install -g @angular/cli, create an app with ng new, and run it with ng serve, which rebuilds and reloads the browser whenever you save. Add packages such as Bootstrap with npm install.
Novice · Angular · Updated
After this lesson you can
- Install the Angular CLI, create an app with ng new, and run it with ng serve
Key takeaways
npm install -g @angular/cliinstalls thengcommand once, globally, so it works in any folder.ng new northwind-angularcreates an app, andng servein its folder runs it at http://localhost:4200.- While
ng serveruns, saving a file rebuilds the app and reloads the browser for you. Stop it with Ctrl+C. - Add a package such as Bootstrap with
npm install bootstrap, list its CSS inangular.jsonunderstyles, then restartng serve.
Installing the CLI
The Angular CLI is an npm package. Install it once, globally (-g), so the ng command works in any folder:
npm install -g @angular/cli
ng version
ng version prints the CLI's version, 22 or later, with Node's and npm's.
Creating an app
In your bootcamp folder:
ng new northwind-angular
The CLI asks a few questions. Choose CSS for the stylesheet format and No for server-side rendering, and accept the defaults for anything else. It then creates the project and runs npm install for you, which takes a minute or two.
(You can also give the answers up front: ng new northwind-angular --style=css --ssr=false.)
Running it
cd northwind-angular
ng serve
➜ Local: http://localhost:4200/
Open http://localhost:4200 in your browser, and there's your app: Angular's welcome page.
ng serve builds the app and keeps running. Change a file and save, and it rebuilds and reloads the browser for you: no restarting. Stop it with Ctrl+C. (npm start does the same: it's listed in package.json's scripts.)
Open the project folder in VS Code, and install the Angular Language Service extension when VS Code suggests it: it adds autocomplete and error checking inside your templates.
Adding Bootstrap
You've styled pages with Bootstrap; Angular apps can use it too. Install it into the project:
npm install bootstrap
Then tell Angular to include its CSS, in angular.json, under build, options, styles:
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
]
Restart ng serve (changes to angular.json need a restart), and every component can use Bootstrap's classes.
Check yourself
1 question to try on the lesson page.
So what
npm install -g @angular/cli once, then ng new and ng serve for every app. Keep ng serve running while you work, and the browser shows every change the moment you save.