Playbook

01. REST API Design Principles02. HTTP Methods and Status Co...03. Backend Fundamentals: 0104. Backend Fundamentals: 0205. GitHub OAuth in Node.js Ap...06. Google OAuth in Node.js Ap...07. MongoDB Aggregation08. Introduction to YAML09. Basics Concepts of Normali...10. Setting Up ESLint, Commit...11. Replication and Sharding12. Introduction to Redis13. Introduction to Kafka
Profile
Akkal DhamiFull Stack Developer

Building modern web experiences with a focus on performance, scalability, and clean architecture.

© 2026 | Akkal Dhami | All rights reserved

Built with
byAkkal Dhami

Navigation

  • Projects
  • Dev Setup
  • Playbook
  • Templates
  • Networking
  • SQL - MySQL
  • SQL Playground
  • DSA
AKKAL DHAMIAKKAL DHAMIAKKAL DHAMI

YAML Basics

YAML stands for YAML Ain't Markup Language.

It is mainly used for:

  • Configuration files
  • DevOps tools
  • APIs
  • Docker
  • Kubernetes
  • CI/CD pipelines

1. YAML Syntax Basics

Rules

  • Uses indentation (spaces)
  • No tabs
  • Usually .yaml or .yml
  • Key-value format

Common Data Types

TypeExample
Stringname: Akkal
Numberage: 20
BooleanisAdmin: true
Array- JavaScript
Objectuser:
Nullvalue: null

2. Key-Value Pair

first.yaml
name: Akkal
age: 22
city: Kathmandu

Meaning

  • name → key
  • Akkal → value
Equivalent JSON:
{
  "name": "Akkal",
  "age": 22,
  "city": "Kathmandu"
}

3. Strings

string.yml
message: Hello World
language: "TypeScript"
framework: 'Express'

Quotes are optional unless special characters exist.


4. Numbers and Boolean

num_bool.yml
age: 22
price: 99.99
 
isAdmin: true
isLoggedIn: false

5. Arrays (Lists)

array.yml
# method - 1
numbers: [1, 2, 3, 4]
 
# method - 2
languages:
  - JavaScript
  - TypeScript
  - Python

6. Objects

object.yml
user:
  name: Akkal
  age: 22
  role: developer

7. Nested Objects

nested_obj.yml
user:
  name: Akkal
  age: 22
 
  address:
    country: Nepal
    city: Kathmandu
    zip: 44600
Structure:
user
 ├── name
 ├── age
 └── address
      ├── country
      ├── city
      └── zip
nested_nested_obj.yml
company:
  name: XYZ
 
  department:
    name: Engineering
 
    manager:
      name: Akkal
      experience: 5
Structure:
company
 └── name
 └── department
      └── name
      └── manager
           ├── name
           └── experience

8. Array of Objects

arr_of_obj.yml
users:
  - name: Akkal
    role: admin
 
  - name: Ram
    role: user

9. Comments

comment.yml
# This is comment
name: Akkal

10. Null Values

null.yml
middleName: null
nickname:
username: ~

11. Multiline Strings

Pipe | : preserve line breaks

multi_line_str.yml
message: |
  Hello
  This is YAML
  Learning basics
Output:

Hello This is YAML Learning basics


Greater Than > : single line

multi_line_str.yml
message: >
  Hello
  This becomes
  one line
Output:

Hello This becomes one line


12. Environment Example

env.yml
app:
  name: auth-service
  port: 5000
 
database:
  host: localhost
  port: 5432
  username: postgres
  password: secret

13. Anchors and Defaults

YAML supports reusable default blocks using anchors & and aliases *.

default_settings is reused in both environments.

anchor_default.yml
default: &default_settings
  timeout: 30
  retries: 3
 
development:
  <<: *default_settings
  host: localhost
 
production:
  <<: *default_settings
  host: prod.server.com

14. Explicit Data Types

value: !!str 123
 
age: !!int "22"
 
isAdmin: !!bool "true"
 
data: !!null ""

15. Docker Compose

15.1 Simple Node.js App

docker-compose.yml
version: "3"
 
services:
  app:
    image: node:20
    container_name: my-node-app
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    working_dir: /app
    command: npm start

15.2. Node.js + MongoDB

docker-compose2.yml
version: "3"
 
services:
  app:
    image: node:20
    container_name: backend-app
    ports:
      - "5000:5000"
    volumes:
      - .:/app
    working_dir: /app
    command: npm run dev
    depends_on:
      - mongo
 
  mongo:
    image: mongo
    container_name: mongodb
    ports:
      - "27017:27017"
    volumes:
      - mongo-data:/data/db
 
volumes:
  mongo-data:

15.3. Node.js + PostgreSQL

docker-compose3.yml
version: "3"
 
services:
  app:
    image: node:20
    ports:
      - "5000:5000"
    environment:
      - DATABASE_URL=postgres://postgres:password@db:5432/mydb
    depends_on:
      - db
 
  db:
    image: postgres
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=mydb
    ports:
      - "5432:5432"
07. MongoDB Aggregation
09. Basics Concepts of Normalization