Sub topic 4
Creating a New App with ng new
This chapter assumes the Angular CLI is installed globally (covered in the previous chapter) and that you can run ng version without errors. It also assumes you are comfortable with a terminal, npm, and basic Git. This chapter covers what ng new does, the choices it asks you to make, the flags that control it, and the errors people most often hit. Later chapters tour the generated files and run the app.
What ng new actually does
ng new is a CLI command that creates an Angular workspace, which is a folder holding configuration, dependencies, and one or more projects. By default it also creates one application project inside that workspace, with the same name as the workspace.
The command does more than copy template files. It runs a series of steps in order:
- It checks that you are not already inside an Angular workspace and that your Node.js version is supported.
- It asks you any questions you did not answer with flags.
- It runs schematics, which are code generators that write files from templates. The
@schematics/angularpackage provides theworkspaceandapplicationschematics. - It installs npm dependencies with your chosen package manager.
- It initializes a Git repository and makes an initial commit.
Knowing the steps helps when something fails. A failure at step 4 still leaves a complete set of files on disk. You can fix the cause and run npm install yourself without starting over.
Running it interactively
The simplest way to run it is to give a name and answer the prompts:
ng new my-appThe exact prompts depend on your CLI version, but they usually include:
- Stylesheet format: CSS, SCSS, Sass, or Less. Some newer versions also offer Tailwind CSS. The choice sets the extension of every generated component stylesheet and configures the build to compile it.
- Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering): answering yes adds the
@angular/ssrpackage, aserver.tsentry point, and server build configuration. - Tooling questions in recent versions, for example whether to add configuration files for AI coding assistants.
Some things are no longer asked about because they are on by default in current versions. Projects use standalone components and include a routes file (app.routes.ts) wired up through provideRouter. Older tutorials that show --routing prompts or app.module.ts files describe earlier defaults.
Choosing a project name
The name becomes the folder name, the name field in package.json, and the project key in angular.json. Use lowercase kebab-case that starts with a letter, such as my-app or inventory-dashboard. The CLI rejects names that are not valid npm package names. Names that start with a digit or contain spaces cause errors, and so do some characters that cannot appear in a TypeScript identifier.
If you want the folder name to be different from the project name, use --directory:
ng new inventory-dashboard --directory=frontendThis creates the workspace in ./frontend, and the project inside it is still called inventory-dashboard.
Running it non-interactively
Interactive prompts are a problem in scripts, CI jobs, and documentation that must give the same result every time. You can supply every answer as a flag, or tell the CLI to accept defaults:
ng new my-app --style=scss --ssr=false --defaults--defaults uses the default value for any option you did not pass. --interactive=false turns prompts off completely. Use --defaults together with it, so you know which values were chosen.
Frequently used flags
| Flag | Effect | When to use it | Column | Column | Column |
|---|---|---|---|---|---|
| `--style=css\ | scss\ | sass\ | less` | Sets the component stylesheet format | Always in scripts, to avoid the prompt |
| `--ssr` / `--ssr=false` | Adds or skips server-side rendering setup | Skip it while learning or for internal tools | |||
| `--prefix=inv` | Sets the selector prefix (default `app`) | Large apps or libraries, so selectors such as `inv-header` do not collide | |||
| `--inline-style`, `--inline-template` | Generates styles or templates inside the `.ts` file | Small demos and prototypes | |||
| `--skip-tests` | Skips generating `.spec.ts` files | Throwaway experiments only | |||
| `--skip-install` | Writes the files but does not install packages | Slow networks, custom registries, offline work | |||
| `--skip-git` | Does not initialize a Git repository | Creating the app inside an existing repository | |||
| `--package-manager=npm\ | pnpm\ | yarn\ | bun` | Chooses the installer and records it in `angular.json` | Teams that standardize on a non-npm tool |
| `--directory=path` | Sets the output folder | Monorepos or a fixed folder layout | |||
| `--no-create-application` | Creates an empty workspace with no project | Multi-project workspaces | |||
| `--dry-run` | Prints what would be created without writing anything | Previewing the effect of a flag combination |
Run ng new --help to see the full list for your installed version. The list changes between major releases.
Previewing with a dry run
A dry run lets you see how flags change the output before you commit to them:
ng new my-app --style=scss --inline-template --skip-tests --dry-runThe output lists every CREATE operation with its file path and size. Nothing is written, so no dependencies are installed and no Git repository is created. The note at the end saying that no changes were made confirms this.
Pinning or skipping the global CLI
A globally installed CLI decides which Angular version a new project uses. If your global CLI is old, ng new gives you an old project. You can avoid the global install completely by running a specific CLI version through npx:
npx @angular/cli@latest new my-app --style=css --ssr=falseTo get an earlier major version, for example to match an existing codebase, replace latest with the version number:
npx @angular/cli@19 new legacy-compatible-app --defaultsAfter the workspace exists, run ng commands inside it and they use the CLI version in the project's own node_modules, not the global one. This is why projects keep building after you upgrade the global CLI.
Creating a multi-project workspace
By default the application files go in a src/ folder at the workspace root. If you plan to keep several applications or libraries in one repository, start with an empty workspace and add projects into the projects/ folder:
ng new acme-workspace --no-create-application
cd acme-workspace
ng generate application storefront --style=css --ssr=false
ng generate library ui-kitEach project gets its own entry in angular.json, and all of them share one node_modules and one package.json. You choose this layout at creation time. Moving a single-app workspace to the multi-project layout later means moving files and editing paths by hand.
Common errors and how to fix them
Running inside an existing workspace
If an angular.json file is in the current folder or any parent folder, ng new refuses to run and reports that it must be run outside a workspace. Change to a folder outside the existing project. If you meant to add an app to that workspace, use ng generate application instead.
Unsupported Node.js version
Every CLI release supports a specific range of Node.js versions. An odd-numbered Node release or an LTS release that has reached end of life produces a warning or an error. Switch to an active or maintenance LTS release, for example with a version manager such as nvm, then try again.
Dependency installation fails
Network errors, proxy settings, or a private registry can break step 4. The files are already written, so do not run ng new again into the same folder, because it will fail when it finds the folder already exists. Fix the cause and finish the install yourself:
cd my-app
npm installIf you know in advance that the install will need special handling, pass --skip-install and run the install when you are ready.
Git commit warnings
If Git is installed but user.name and user.email are not configured, the initial commit fails. The CLI prints a warning, but the project is still usable. Configure Git and commit by hand:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
cd my-app
git add -A
git commit -m "Initial commit"Verifying the result
After ng new finishes, check that the workspace is healthy before going further:
cd my-app
ng version
git log --onelineng version run inside the workspace reports the local Angular package versions, and they should all share the same major version. git log should show a single initial commit, unless you skipped Git. The next chapter goes through the files you just created.
Exercise
You need a CI script that creates a fresh Angular app with SCSS, no SSR, the selector prefix "shop", and no Git repository, because the script runs inside an existing repo. The script must never stop at a prompt. Write the command.
Show answer
ng new shop-app --style=scss --ssr=false --prefix=shop --skip-git --defaults --interactive=false. Here --interactive=false stops all prompts, --defaults fills in any option not given, and --skip-git avoids creating a nested repository inside the existing one.
Exercise
ng new my-app wrote all its files but failed during npm install because of a proxy error. A teammate suggests deleting the folder and running ng new again. What is a faster fix, and why does it work?
Show answer
Fix the proxy configuration, then run npm install inside my-app. ng new writes every file with the schematics before it installs dependencies, so the workspace is complete and only node_modules is missing. Running ng new again into the same folder would also fail, because the folder already exists.
Exercise
Your global CLI is version 18, but you want to start a project on the latest Angular release without changing your global install. How do you do it, and which CLI version will ng serve use inside the new project?
Show answer
Run npx @angular/cli@latest new my-app. Inside the workspace, ng commands use the CLI installed in the project's local node_modules, so ng serve runs the latest version that was installed with the project, not the global version 18.