Bittu Kumar’s Post

What Really Happens When We Run ng serve and Open localhost:4200 ? First, you run ng serve. When you run ng serve, Angular CLI reads your project configuration from angular.json. In Angular 17+, it looks for: "browser": "src/main.ts" → the application entry point "sourceRoot": "src" → the base source folder If index is not explicitly defined, the new application builder automatically assumes src/index.html as the root HTML file. Then the build process starts. During compilation, TypeScript files are converted into JavaScript because browsers only understand JavaScript. All modules are bundled into optimized files like main.js, polyfills.js, and other supporting chunks. In development mode, these files are served from memory by the dev server. After building, Angular CLI starts a development server on port 4200. At this stage, the application is compiled and ready, but nothing has executed in the browser yet. Now you open http://localhost:4200 in the browser. The browser sends a request to the local development server. The server responds with the processed index.html file (resolved from src/index.html by default). During the build process, script references to the generated JavaScript files were injected into this HTML file. When the browser loads index.html, it also loads those JavaScript bundles. When main.js loads, it runs the compiled version of main.ts. Inside main.ts, Angular bootstraps the application using: platformBrowserDynamic().bootstrapModule(AppModule) or bootstrapApplication(AppComponent) in standalone apps. Angular initializes the root module or root component and looks for its selector inside index.html — usually <app-root>. Angular then replaces <app-root> with the rendered template of the root component. At this point, the Angular application is running completely inside the browser. Routing, change detection, API calls, and UI updates all happen without full page reloads. In short: ng serve- builds the app and starts the dev server. Opening localhost:4200 loads index.html, executes main.js, and starts the Angular application in the browser. Read my medium article, I write about Angular and JavaScript. https://lnkd.in/ggmhXdvA #angular

To view or add a comment, sign in

Explore content categories