Guide

node-basics.mdx

Updated June 25, 2025

Node.js Basics Guide

What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime environment that executes JavaScript code outside a web browser. It allows developers to use JavaScript to write command-line tools and server-side scripts.

Key Features

  • Non-blocking I/O: Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
  • NPM (Node Package Manager): Provides access to a large ecosystem of open-source packages.
  • Single-threaded but highly scalable: Uses an event loop to handle multiple connections concurrently.

Installation

Install Node.js

Download and install from nodejs.org, or use package managers:

bash

Verify installation:

bash

Creating Your First Node.js Application

  1. Create a directory for your project:
bash
  1. Initialize a new Node.js project:
bash
  1. Create a file named app.js:
javascript
  1. Run your application:
bash

Built-in Modules

Node.js comes with several built-in modules that you can use without installation:

File System (fs)

javascript

HTTP

javascript

Path

javascript

NPM Packages

NPM (Node Package Manager) allows you to install and manage third-party packages.

Installing Packages

bash

Using Packages

javascript

Asynchronous Programming

Node.js is built around asynchronous programming. There are several ways to handle asynchronous operations:

Callbacks

javascript

Promises

javascript

Async/Await

javascript

Event Emitters

Node.js uses an event-driven architecture with many objects that emit events:

javascript

Error Handling

Try-Catch Blocks

javascript

Handling Uncaught Exceptions

javascript

Resources for Further Learning

Debugging Node.js Applications

  • Using the --inspect flag: node --inspect app.js
  • Using Visual Studio Code's built-in debugger
  • Using the debug npm package

Next Steps

  • Learn Express.js for building web applications
  • Explore databases like MongoDB or PostgreSQL with Node.js
  • Study authentication and security in Node.js applications
  • Learn about RESTful API design principles

About This College

M
mattbratos
Hacker College

College

see what I'm learning about recently

This guide is from mattbratos

Back to Feed