Node.js LFW111

Quick Reference & Exam Preparation Guide

Linux Foundation Introduction to Node.js Exam Focus
Exam Strategy

Focus on concepts, not deep coding. Remember: Node.js is best for I/O operations, worst for CPU-intensive tasks.

Flashcards (Hover to Flip)

Node.js Main Advantage?

Hover to reveal answer

Concept Architecture
Answer:

Non-blocking I/O & Event Loop

Single-threaded asynchronous architecture that handles many connections efficiently.

Best Use Cases for Node.js?

Hover to reveal answer

Application Scenario
Answer:
  • ✓ APIs & Microservices
  • ✓ Real-time applications
  • ✓ Data streaming
  • ✓ CLI tools
  • ✓ Proxy servers
Worst Use Cases for Node.js?

Hover to reveal answer

Limitations Scenario
Answer:
  • ✗ CPU-intensive calculations
  • ✗ Heavy computational tasks
  • ✗ Image/video processing
  • ✗ Machine learning algorithms

(Use Worker Threads or other languages for these)

What is npm?

Hover to reveal answer

Tool Ecosystem
Answer:

Node Package Manager

World's largest software registry with over 1.5 million packages.

Key commands: npm init, npm install, npm start

Essential Code Examples

Basic HTTP Server MUST KNOW
const http = require('http');

const server = http.createServer((req, res) => {
  // Set response header
  res.writeHead(200, {'Content-Type': 'text/plain'});

  // Send response
  res.end('Hello World\n');
});

// Listen on port 3000
server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

This is the most basic Node.js server. Must know for exam.

Module System IMPORTANT
// myModule.js - Exporting
const myFunction = () => {
  return 'Hello from module!';
};

module.exports = { myFunction };

// app.js - Importing
const myModule = require('./myModule');
console.log(myModule.myFunction());

CommonJS modules (require/exports) vs ES6 modules (import/export).

Essential NPM Commands
Command Purpose
npm init -y Initialize project with default settings
npm install express Install Express framework
npm install --save-dev nodemon Install dev dependency
npm start Run start script from package.json
npm run dev Run custom "dev" script

Exam Quick Reference

Key Concepts
  • Event Loop: Handles async operations
  • Non-blocking I/O: Core advantage
  • Single-threaded: But scalable via clustering
  • CommonJS: Original module system
  • npm: Package manager ecosystem
Core Modules
  • http/https - Web servers
  • fs - File system operations
  • path - File/directory paths
  • os - Operating system info
  • events - Event handling
  • util - Utility functions
Exam Patterns
  • "Best for..." → APIs, I/O, real-time
  • "Not suitable for..." → CPU-intensive
  • "Creator of Node.js" → Ryan Dahl
  • "Built on..." → V8 JavaScript engine
  • "Package manager" → npm