Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Runtime APIs are extra features provided by the environment (browser or Node.js) where your JavaScript runs. They're not part of JavaScript itself - they're bonus tools!
Works everywhere - part of the language itself
Provided by browser or Node.js - environment-specific
Manipulate HTML elements on the page
Make HTTP requests to servers
Store data in the browser
Get user's location
Draw graphics and animations
Process and play audio
Read and write files on the computer
Create web servers and make requests
Work with file and directory paths
Get system information
Current Node.js process info
Cryptographic operations
// ✅ These Runtime APIs work EVERYWHERE
// 1. console - debugging output
console.log('Hello');
console.error('Error occurred');
console.table([{name: 'Alice', age: 25}]);
// 2. setTimeout & setInterval - timers
setTimeout(() => {
console.log('After 1 second');
}, 1000);
const interval = setInterval(() => {
console.log('Every 2 seconds');
}, 2000);
clearInterval(interval);
// 3. fetch - HTTP requests (modern Node has it!)
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
// 4. URL - parse URLs
const url = new URL('https://example.com/path?query=value');
console.log(url.hostname); // 'example.com'
// 5. Crypto (Web Crypto API in browser, crypto in Node)
// Available with slight differences
// 6. TextEncoder / TextDecoder
const encoder = new TextEncoder();
const encoded = encoder.encode('Hello');// Use fetch API
fetch('data.json')
.then(response => response.json())
.then(data => {
console.log(data);
});
// Or from a server
fetch('https://api.example.com/users')
.then(response => response.json())
.then(users => {
// Display in DOM
document.getElementById('users')
.innerHTML = users.map(u =>
`<li>${u.name}</li>`
).join('');
});// Use fs module
const fs = require('fs');
const data = fs.readFileSync(
'data.json',
'utf8'
);
const parsed = JSON.parse(data);
console.log(parsed);
// Or from a server
const https = require('https');
https.get('https://api.example.com/users',
(res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
const users = JSON.parse(body);
console.log(users);
});
});APIs not in JS core
Provided by environment
DOM, fetch, localStorage
Web-specific features
fs, http, path, os
Server & system features
console, fetch, setTimeout
Work in both environments