Introduction to Node.js Β· Astro Tech Blog

What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime that lets you run JavaScript outside the browser. Built on Chrome’s V8 engine, it brings JavaScript to the server, command line, and even IoT devices.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  JavaScript  β”‚
β”‚   (your      β”‚
β”‚    code)     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Node.js     β”‚
β”‚  APIs        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  V8 Engine   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  OS Layer    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why Node.js?

Before Node.js (2009), JavaScript was trapped in the browser. Developers had to learn a different language (PHP, Python, Ruby, Java) to write backend code. Node.js changed that by:

  • Unifying language β€” use JavaScript everywhere
  • Non-blocking I/O β€” handle thousands of concurrent connections with a single thread
  • NPM ecosystem β€” the largest package registry on earth

Who Uses Node.js?

CompanyUse Case
NetflixFaster startup & rendering
UberHigh-throughput data processing
PayPalUnified frontend/backend stacks
LinkedInMobile server architecture
WalmartReal-time inventory

Your First Node.js Script

Create a file hello.js:

// hello.js
console.log('Hello, Node.js!');
console.log('Running on', process.version);

Run it:

node hello.js
# Output:
# Hello, Node.js!
# Running on v22.x.x

Note: The exact version depends on what you have installed. This is fine β€” all code in this tutorial works across modern Node.js versions.

Node.js is Event-Driven

Node.js uses an event-driven, non-blocking I/O model. Instead of waiting for a file to read or a database to respond, it registers a callback and moves on:

// non-blocking.js
const fs = require('fs');

console.log('1. Start reading file...');

fs.readFile('hello.js', 'utf8', (err, data) => {
  if (err) throw err;
  console.log('3. File read complete');
});

console.log('2. Done! (but file read is still in progress)');

Output:

1. Start reading file...
2. Done! (but file is still in progress)
3. File read complete

Node.js vs Traditional Servers

Traditional (PHP, Python, Ruby)Node.js
Concurrency modelMulti-threaded (one thread per request)Single-threaded + event loop
Blocking I/OYes β€” thread waitsNo β€” callback is queued
Memory usageHigher (many threads)Lower (single thread)
Best forCPU-heavy tasksI/O-heavy apps (APIs, real-time)

Key Takeaways

  • Node.js is a JavaScript runtime for the server, not a framework
  • Built on the V8 JavaScript engine
  • Uses non-blocking, event-driven I/O for high concurrency
  • npm provides access to over 2 million packages
  • Perfect for APIs, real-time apps, CLIs, and microservices