Setup dotenv to Access Environment Variables in Angular 9

Keeping sensitive information like API keys safe

#security #web-development #angular #technology #software-development

What is GEEK

Buddha Community

Setup dotenv to Access Environment Variables in Angular 9
Christa  Stehr

Christa Stehr


Install Angular - Angular Environment Setup Process

Angular is a TypeScript based framework that works in synchronization with HTML, CSS, and JavaScript. To work with angular, domain knowledge of these 3 is required.

  1. Installing Node.js and npm
  2. Installing Angular CLI
  3. Creating workspace
  4. Deploying your First App

In this article, you will get to know about the Angular Environment setup process. After reading this article, you will be able to install, setup, create, and launch your own application in Angular. So let’s start!!!

Angular environment setup

Install Angular in Easy Steps

For Installing Angular on your Machine, there are 2 prerequisites:

  • Node.js
  • npm Package Manager

First you need to have Node.js installed as Angular require current, active LTS or maintenance LTS version of Node.js

Download and Install Node.js version suitable for your machine’s operating system.

Npm Package Manager

Angular, Angular CLI and Angular applications are dependent on npm packages. By installing Node.js, you have automatically installed the npm Package manager which will be the base for installing angular in your system. To check the presence of npm client and Angular version check of npm client, run this command:

  1. npm -v

Installing Angular CLI

  • Open Terminal/Command Prompt
  • To install Angular CLI, run the below command:
  1. npm install -g @angular/cli

installing angular CLI

· After executing the command, Angular CLI will get installed within some time. You can check it using the following command

  1. ng --version

Workspace Creation

Now as your Angular CLI is installed, you need to create a workspace to work upon your application. Methods for it are:

  • Using CLI
  • Using Visual Studio Code
1. Using CLI

To create a workspace:

  • Navigate to the desired directory where you want to create your workspace using cd command in the Terminal/Command prompt
  • Then in the directory write this command on your terminal and provide the name of the app which you want to create. In my case I have mentioned DataFlair:
  1. Ng new YourAppName

create angular workspace

  • After running this command, it will prompt you to select from various options about the CSS and other functionalities.

angular CSS options

  • To leave everything to default, simply press the Enter or the Return key.

angular setup

#angular tutorials #angular cli install #angular environment setup #angular version check #download angular #install angular #install angular cli

Clara  Gutmann

Clara Gutmann


Angular Sass: How To Use Sass In Angular 9 Tutorial

Angular supports Sass, CSS, and Less to style global application styles as well as component styles. Angular components styles have an effective CSS encapsulation mechanism that assures any component CSS is local to the component and does not globally alter any styles.

Angular Sass Example

Why use Angular Sass? Well!! Sass (Syntactically Awesome Style Sheets) is an extension of CSS that allows you to use things like variables, nested rules, inline imports, and more. It also supports you to keep things organized and enables you to create style sheets faster.

In short,  Sass is a CSS preprocessor, which combines unique features such as variables, nested rules, and mixins (sometimes referred to as syntactic sugar) into regular CSS. The main object of Sass is to make the CSS coding process more comfortable and more efficient.

Sass is compatible with all versions of CSS. When working with the Angular CLI, the default stylesheets have the .css extension. We are using Angular CLI 8. So, if you have not used previously, then please upgrade your  CLI version. We will use the Bootstrap 4 Framework for this demo and see how we can configure the Sass in our Angular 9 application.

#angular #angular 9 #angular cli #css #angular sass

Christa  Stehr

Christa Stehr


Playing with Angular Environments

Station Zero

Every angular developer have come across many environments to configure there app with and before angular 5 it was a nightmare to set those configs that only should be run in a specific environment. Earlier this process was time consuming and hectic none the less. But with every new release angular community has dissolved the complexity of this problem. Now, setting up the environment configs is matter of only 10 mins, thanks to Angular CLI.

Setting Angular environments

I am assuming that you already have angular installed and npm setup on your system. If not then please follow this link –

Let’s start the train engine!

As of now Angular 9 is the official version. Therefore we will be creating an angular 9 project and I will walk you through how to set up the environment configs in the project. Every application will probably use at least two environments i.e local (aka development) and production. But larger applications may have several environments like QA, pre-prod, staging, etc.

In our DEMO app, we will have three environments : local (aka development)staging (aka QA) and production.

Run the below command in your terminal and create a new angular project or you can download the whole project from my Github!

ng new yourAngularApp

Go to src/environments and you will see two files there : –

  2. environment.ts

env files in the project directory

What are these two environment files that the CLI generates with every new project?

An environment file in the angular application is a JSON configuration information file that tells the build system which files to change for which environment when you use ng build and ng serve.

  • is the configuration file that the CLI injects for us when the app is built using the production configuration
  • environment.ts is the configuration default file we reference in our application, and the CLI will take care of getting the correct configuration at build time.

Imagine you have a back-end REST API deployed on a server that provides services to your Angular app. At local, the service URL will be different from that on staging or that on the production. Then, you might be juggling through the app again and again so that it can be used in different environments. Here, you can just define the URL of the service to each of the app environments files and see the magic happen.

Let’s play with code now

Edit environment.ts file with the following code –

export const environment = {
  production: false,
  name: 'local',

Edit file with the following code –

export const environment = {
  production: true,
  name: 'production',

NOTE: Remember never put any sensitive information in these environment files.

Edit app.component.ts file with following code –

import {Component} from '@angular/core';
import {environment} from "../environments/environment";

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
export class AppComponent {
  title = 'yourAngularApp';
  envName =;

Now hit this command next –

ng serve --open

Check localhost:4200 on your browser

I have refactored the app.component.html file to my liking, you can do that too. It’s up to you, how you do it, so go ahead and use your brain a little 😀 or you can just use mine from the gitHub repo.

Now, kill the serve command wherever you have run it. And run this now –

ng serve --configuration=production --open


ng s -c=production --open

Check localhost:4200 in your browser

Do you see the change? How this happened? Do you want to see the actual gears being shifted by angular? Ok! ok! hold your horses!

#angular #tech blogs #user interface (ui) #angular #deployment #development environment #environment

Shawn  Durgan

Shawn Durgan


Angular 9 CRUD by Example

Throughout this Angular 9 CRUD tutorial, we’ll be learning to implement CRUD operations by example using the latest Angular 9 version that has been released recently with Ivy support.

> ✋✋ Join our Facebook group 👈 to discuss anything related to Angular development.

We’ll make use of a CRUD REST API built using json-server which allows you to generate a full working REST API in no time.

What’s CRUD?

CRUD stands for Create, Read. Update and Delete — a set of operations often implemented in web apps to allow users to interact with a database.

In our tutorial, we’ll only focus on building the front-end using Angular 9, the back-end will be mocked using json-server.

We’ll not be learning how to use json-server but you can see the complete instructions from this tutorial after creating the Angular 9 project.

Angular 9 CRUD Tutorial Steps

  • Step 1 — Mocking the Backend Using json-server
  • Step 2 — Creating an Angular 9 Module
  • Step 3 — Importing Angular HttpClientModule and FormsModule
  • Step 4 — Creating Angular 9 Component(s)
  • Step 5 — Adding Angular 9 Routing
  • Step 6 — Creating an Angular 9 Service
  • Step 7 — Creating a Model
  • Step 8 — Implementing the CRUD Methods
  • Step 9 — Calling the CRUD Methods

#angular #angular-9 #angular 9 crud

Setup dotenv to Access Environment Variables in Angular 9

Keeping sensitive information like API keys safe

#security #web-development #angular #technology #software-development