Sub topic 3
Tour of the workspace root files
This chapter assumes you have run ng new my-app and can open the resulting folder in an editor. You should know what npm does and be able to read JSON. The goal is to learn what each file at the top of the workspace is for, which ones you edit by hand, and which ones you leave alone.
What you see after `ng new`
A new workspace has a handful of files and folders at its top level. Exact contents vary by CLI version and by the options you chose at the prompts, but a recent workspace looks like this:
my-app/
├── .angular/
├── .vscode/
├── node_modules/
├── public/
├── src/
├── .editorconfig
├── .gitignore
├── angular.json
├── package.json
├── package-lock.json
├── README.md
├── tsconfig.json
├── tsconfig.app.json
└── tsconfig.spec.jsonThe files fall into four groups: configuration the CLI reads, package management, editor and Git support, and generated folders you never commit.
package.json and package-lock.json
package.json is the standard npm manifest. For an Angular app it does three jobs: it names the project, defines npm scripts, and lists dependencies.
{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/core": "^19.0.0",
"@angular/router": "^19.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular/cli": "^19.0.0",
"@angular/compiler-cli": "^19.0.0",
"typescript": "~5.6.2"
}
}This is a trimmed excerpt. A real file lists more @angular/* packages, and the version numbers match whichever CLI created the workspace.
Points worth knowing:
- The
scriptsentries are thin wrappers.npm startrunsng serve, andnpm testrunsng test. The"ng": "ng"script lets you runnpm run ng -- generate component foousing the project's local CLI. dependenciesare packages the running application needs.devDependenciesare build-time tools. The Angular build bundles only what your code imports, so this split matters less for browser apps than for Node servers, but keep it accurate.@angular/cliis listed as a dev dependency. This is why a project builds with the version it was created with, even if your globally installed CLI is newer. When you runnginside a workspace, the global CLI hands off to the local one.- The
^prefix allows minor and patch updates. The~prefix allows only patch updates. Angular packages move together, so mismatched major versions among@angular/*packages are a common source of confusing errors.
package-lock.json records the exact version of every package that was installed, including transitive dependencies. Commit it. Without it, two developers running npm install on different days can get different dependency trees. In CI, use npm ci, which installs exactly what the lock file says and fails if it disagrees with package.json.
If you chose another package manager at ng new time, you will see yarn.lock, pnpm-lock.yaml, or bun.lock instead. Keep one lock file only.
angular.json
angular.json is the CLI's own configuration file. It lists the projects in the workspace and, for each one, the targets (build, serve, test) and the builders that run them. When you type ng build, the CLI reads this file to learn which builder to run and with which options. A later chapter reads it line by line, so for now remember two facts:
- It is the file you edit to change how the app is built, such as adding a global stylesheet or a new build configuration.
- Its
sourceRootandbrowseroptions tell the CLI where your code starts. Movingsrcwithout updating them breaks the build.
The tsconfig files
Three TypeScript configuration files sit at the root.
| File | Purpose |
|---|---|
| `tsconfig.json` | Base settings shared by everything: strictness flags, target, module resolution, and Angular compiler options |
| `tsconfig.app.json` | Extends the base. Adds the application's entry file and excludes test files |
| `tsconfig.spec.json` | Extends the base. Includes test files and adds test type definitions |
The split means the production build never compiles your tests, and the test build gets the testing types. Both derived files use "extends": "./tsconfig.json", so a setting you change in the base file applies to both.
A new workspace turns on "strict": true in the base file, along with the Angular-specific strictTemplates option under angularCompilerOptions. Leave these on. Turning them off hides errors that would otherwise appear at build time and surfaces them as runtime bugs.
The src and public folders
src/ holds your application code: main.ts, the root component, global styles, and index.html. The next chapters cover it in detail.
public/ appeared in Angular 18 and later. Files placed there, such as the favicon or images, are copied to the build output as-is. In older workspaces, this role belonged to src/assets/. If you follow an older tutorial that mentions assets, check which layout your workspace uses, because the assets option in angular.json must point at the right folder.
Editor and Git support files
.editorconfig tells editors how to format files: indentation, line endings, and charset. A new workspace uses two-space indentation and single quotes in TypeScript. Most editors honor it through a built-in feature or a plugin.
.gitignore keeps generated content out of version control. These entries matter most:
/dist
/tmp
/out-tsc
/node_modules
/.angular/cache
.sass-cache/.vscode/ contains suggested settings for Visual Studio Code, such as recommended extensions and launch configurations for debugging. It is optional and safe to delete if you use another editor.
README.md is a stub that lists the common commands. Replace it with documentation for your own project.
Generated folders you do not edit
Two folders are created by tools and should never be committed or edited by hand:
node_modules/is where npm installs dependencies. If it is damaged or out of date, delete it and runnpm installagain..angular/is the CLI's cache. It speeds up repeat builds. If you see stale build results that make no sense, delete.angular/and rebuild. Deleting it is always safe.
After ng build, a dist/ folder also appears, holding the compiled output.
Which files do you edit?
| File | How often you edit it |
|---|---|
| `src/**` | Constantly |
| `package.json` | Rarely by hand. Usually through `npm install`, `ng add`, and `ng update` |
| `angular.json` | Occasionally, for build options, assets, and configurations |
| `tsconfig*.json` | Rarely, to change compiler options |
| `package-lock.json`, `.angular/`, `node_modules/` | Never by hand |
Common mistakes
- Committing
node_modules/or.angular/because.gitignorewas deleted or edited. - Ignoring
package-lock.jsonin Git, then getting different dependency versions on each machine. - Mixing package managers, which leaves two lock files that disagree.
- Upgrading one
@angular/*package by hand while the others stay on an older major version. Useng updateinstead, which a later chapter covers. - Moving
src/orpublic/without updating the matching paths inangular.jsonandtsconfig.app.json.
Exercise
A teammate clones your repository and runs ng serve, but gets "ng: command not found" or a dependency error. They did not install anything yet. Which root file tells them what to install, which file makes sure they get the same versions you have, and which command should they run in a CI pipeline to enforce that?
Show answer
package.json lists the dependencies, and package-lock.json pins the exact versions. They should run npm install locally to populate node_modules/. In CI, npm ci installs exactly what the lock file records and fails if it does not match package.json. Because @angular/cli is a dev dependency, npx ng serve or npm start also works without a global install.
Exercise
You want unit tests to use Jasmine types without those types being visible to the production build. Which tsconfig file would you put them in, and why does the base tsconfig.json stay unchanged?
Show answer
Put them in tsconfig.spec.json, which the test target in angular.json uses. tsconfig.app.json does not include them, so the production build never sees test types. The base file holds only settings shared by both, so test-specific options do not belong there.