Node.js

Free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.

Álvaro José Agámez Licha

Senior Software Engineer

https://github.com/aagamezl

https://x.com/aagamezl

The backend is the server-side part of a software application that handles data processing, business logic, and database interactions. It runs on remote servers, processes requests from the frontend (client side), and sends back appropriate responses.

What is Backend?

Hypertext Transfer Protocol (HTTP) is the foundation of web communication, defining how clients (browsers) and servers exchange requests and responses.  

 

Key HTTP Methods (Verbs):

  • GET: Fetch data (e.g., loading a webpage).  
  • POST: Submit new data (e.g., form submission).  
  • PATCH/PUT: Update existing data.  
  • DELETE:Remove data.

HTTP & REST Basics

To understand how HTTP messages work, we'll look at HTTP/1.1 messages:

HTTP & REST Basics

The following table lists HTTP request methods and their categorization in terms of safety, cacheability, and idempotency.

HTTP Request Methods

Method Safe Idempotent Cacheable
GET Yes Yes Yes
HEAD Yes Yes Yes
OPTIONS Yes Yes No
TRACE Yes Yes No
PUT No Yes No
DELETE No Yes No
POST No No Conditional*
PATCH No No Conditional*
CONNECT No No No

HTTP Response Status Codes

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:

 

  1. Informational responses (100 – 199)
  2. Successful responses (200 – 299)
  3. Redirection messages (300 – 399)
  4. Client error responses (400 – 499)
  5. Server error responses (500 – 599)

Informational Responses (1xx)

"Hold on, I’m thinking…" 🤔 (Server’s still loading, like your WiFi in a basement).

"Mission accomplished! 🎉 (rare like a perfect avocado in Europe 🥑)"

Successful Responses (2xx)

Oops, wrong address. Try this link. 🏃‍♂️💨" (The internet’s way of ghosting you to a new URL).

Redirection Messages (3xx)

 "You had ONE job…" 😤 (you messed up, I can't believe it).

Client Error Responses (4xx)

"My bad, I’ll just… crash 💥" (server’s on strike. Blame the intern).

Server Error Responses (5xx)

HTTP Status Codes: The Drama Edition 🎭

Code Name Meme Description
200 OK Everything worked!. (rare like a perfect avocado in Europe 🥑)
201 Created New resource born! Name it wisely
204 No Content Success! So clean and empty... like my desk on New Year's Day! 🧹💫
400 Bad Request You sent garbage. The server's judging you
401 Unauthorized Oops! Did you forget your keys again? 🔑 Time for a coffee break while you reset your password! ☕😊
403 Forbidden You shall not pass! 🧙‍♂️ (Even if you brought coffee
404 Not Found Whoops! This page went on vacation! 🏖️ Maybe try the homepage instead? 🏠💡
405 Method Not Allowed Nope. Try again, hacker boi
500 Internal Server Error The server's on strike. (Blame the intern)
502 Bad Gateway The backend is ghosting us
503 Service Unavailable Server's taking a nap
  • Node.js is a runtime environment that allows you to run JavaScript code outside of a browser.

 

What Is Node.js?

npm is the world's largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.

 

npm consists of three distinct components:

NPM - Build Amazing Things

  • Meaningful names for variables, constants and functions
  • Always add the .gitignore
  • Give some love to your code, companies care about code quality
  • Blank lines are free, use them to separate your logic blocks
  • Use 2 spaces for indentation
  • Add comments to your code for why not what

Let's Care About Quality

  • You cheat yourself
  • Job interviews don’t allow AI
  • Struggle teaches you valuable skills
  • You’ll build a false sense of confidence
  • You're not really learning
  • It's really quite obvious

Let's Avoid Using Any LLM

Let's Avoid Using Any LLM

Every time you use an LLM unnecessarily, a puppy dies.

Coding Time

Starting A Node.js Project

# Create a Project Folder
mkdir my-node-project
cd my-node-project

# Initialize the Project
npm init -y

# Create an Entry File
touch index.js

# Write Basic Code in index.js
console.log('Hello from Node.js!');

# Run Your App
node index.js
{
  "name": "your-project-name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Anatomy Of package.json

HyF Node.js Week 01

By Alvaro Agamez

HyF Node.js Week 01

  • 62