Getting Started with Node.js
Creating Your First Node.js Project
Step 1: Initialize a Node Project
mkdir node-app
cd node-app
npm init -y # This creates a package.json file, which stores project metadata and dependencies.
Note - When you install packages, they are stored in the node_modules folder.
Step 2: Create Entry File
// index.js
console.log("Hello, Node.js!");
Run with:
node index.js
Note - Each file in Node.js is treated as a module with its own scope (not global like in browsers).
How Node Executes your Code
- Node.js starts its runtime (V8 engine + libuv).
- Loads your JavaScript file.
- Parses and compiles it.
- Executes it inside the event loop.
- Exits when no more work remains.
If you create a server or set timers, the event loop stays active, keeping your program running.