Node.js Environment
Node.js Environment
Section titled “Node.js Environment”Node.js lets you run JavaScript outside the browser — on servers, desktops, and IoT devices.
Visual Explanation
Section titled “Visual Explanation”flowchart TD A["📄 app.js"] --> B["🖥️ Node.js"] B --> C["⚙️ V8 Engine"] C --> D["📁 File System"] C --> E["🌐 HTTP Module"] C --> F["🔌 Streams"] C --> G["📦 npm Packages"]
style B fill:#059669,color:#fff style G fill:#cb3837,color:#fffInstallation
Section titled “Installation”- Go to nodejs.org
- Download the LTS version
- Run the installer
- Verify:
node --version # e.g., v22.x.xnpm --version # e.g., 10.x.xRunning JavaScript with Node.js
Section titled “Running JavaScript with Node.js”# Run a filenode app.js
# Open the REPL (interactive shell)node> console.log("Hello from Node.js!")> .exitExample
Section titled “Example”// app.js — server-side JavaScriptconst fs = require("fs");
fs.writeFileSync("hello.txt", "Hello from Node.js!");console.log("File created!");node app.js# File created!# Check your directory — hello.txt exists!