Understanding Angular CLI (Angular interview questions part 1)

1. What is Angular CLI?
Angular CLI is a command line interface used to develop, build and deploy angular application using command shell only. It basically generates the project structure just by a simple command, run or launch, configure and many more with the help of a command shell.
We can install angular cli by a command :  npm install -g @angular/cli

2. Difference between npm install and npm install -g?
Basically both npm install and npm install -g are used to install any module, but the difference lies on where actually they install those modules. 
    Let's take an example, We need to install @angular/cli, If we used npm install @angular/cli command i.e. without -g, the module will get installed in the local directory of a project under node_modules. But if we use npm install -g @angular/cli i.e. with -g then it will install the module globally not for a single project but for all the projects that will be developed using that device.

3. What does ng serve command do?
When this command is hit the compilation of application starts and when done it launches the application on a local server with port 4200 i.e. localhost:4200. This is done by hosting the app in memory and serving via webpack-dev-server.

4. What is the difference between ng serve and ng build?
ng serve and ng build works in a similar way to some extent but they serve a different purpose.

    ng serve builds a project in memory and launch in a local server (localhost:4200). Also it keeps track of changes made in the project and reloads the browser to reflect the changes.

    ng build is used to generate the final deployable file. It works with some volatile memory like hard-disk. When the file is built a new folder called dist is created and it holds the built file that can be deployed.

5. What is the purpose of ng build --prod flag?
 ng build --prod can be said as the improved version of ng build. The file created by ng build command are not optimized and occupy more space but with --prod flag this is not the case. --prod flag helps in optimization of the code and files which also occupies less space. It does so by removing extra comments and white spaces.

6. What is the importance of src and e2e folder?
src folder contain the raw typescript code and the template code and css whereas the e2e folder contains all the tests cases that tests whether the components are fully functioning or not and whether they work as they are expected to. 
     Angular project structure :


Video Tutorial: