Learning Objectives
Understand Node.js
Runtime, V8 engine, backend development.
Installation
Install Node.js, npm, configure PowerShell.
Programming
REPL, JavaScript files, app.js, index.js.
What is Node.js?
Node.js is a JavaScript runtime environment built on Google's V8 JavaScript Engine. It allows JavaScript to run outside the browser and is widely used for backend applications, APIs, command-line tools and real-time applications.
Runtime & V8 Engine
JavaScript
Developer writes code.
Node Runtime
Executes JavaScript outside browsers.
V8 Engine
Compiles JavaScript into machine code.
Output
Console, API or Server.
Event Loop
Node.js uses an event-driven, non-blocking architecture. Long-running I/O tasks are delegated while the event loop continues processing other work.
| Blocking | Non-Blocking |
|---|---|
| Waits for file/database | Continues executing other tasks |
| Lower concurrency | High concurrency |
Installation
- Download the official MSI installer.
- Install Node.js.
- Keep "Add to PATH" enabled.
- Verify using
node -vandnpm -v. - Configure PowerShell if required.
node -v npm -v Get-ExecutionPolicy Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Node.js REPL
> 10+20
30
> function add(a,b){
... return a+b;
... }
> add(5,10)
15
.exit
Executing Scripts
// app.js
console.log("Hello Node.js");
node app.js
Unit Summary
- Node.js is a runtime environment.
- Uses Google's V8 Engine.
- Supports asynchronous non-blocking I/O.
- Includes npm.
- REPL is useful for testing.
- Run programs using node filename.js.