View video tutorial

ANGULAR ng serve

ANGULAR

The Angular ng serve command allows the application to be built locally and served through the local default browser.

The ng serve command in angular


➔ The ng serve is used to build and serve Angular applications through a local development server and the default browser.

The basics of the ng serve command


➔ This command has an alias ng s which is a shortcut for ng serve.

➔ This launches a local development server that typically displays the application's output on port 4200.

➔ When a change is made to the code, it rebuilds the application and reloads the browser, displaying the output with the changes and effects.

➔ Unlike the ng build command, ng serve does not create a dist folder on disk, but rather it creates the output in memory.

Syntax

ng serve

ng serve --flagname

ng serve --flagshortcut

Example: ng serve command with flags

ng serve --help

ng serve --open

ng serve --port 4200

ng serve --configuration=production

ng serve --ssl

Example ng serve command with flags shortcut:

ng serve -h

ng serve -o

ng serve -c=production

The flag descriptions:

--help (or -h): This displays a help message for the command on the console.

--open (or -o): This will automatically open the application in the default browser with the default port.

--configuration (or -c): Specifies the name of the build target defined in the angular.json file.

--port: This specifies which port number the application should listen on.

--host: This specifies which host the application server runs on. By default it is localhost.

--ssl: This specifies that the application will use the https protocol.

--live-reload: Specifies that the page should reload when a change is detected in the file and is enabled by default.