Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main environment difference between Node.js and browser JavaScript?
Node.js runs JavaScript on the server side outside the browser, while browser JavaScript runs inside the web browser on the client side.
Click to reveal answer
beginner
Which global object is used in Node.js instead of 'window' in browsers?
Node.js uses the 'global' object as the global scope, unlike browsers which use the 'window' object.
Click to reveal answer
intermediate
Can Node.js access the file system directly? Why or why not?
Yes, Node.js can access the file system directly using built-in modules like 'fs' because it runs on the server with system access, unlike browser JavaScript which is sandboxed for security.
Click to reveal answer
intermediate
How does Node.js handle modules compared to browser JavaScript?
Node.js uses CommonJS or ES Modules to organize code into files and packages, while browsers traditionally did not support modules but now support ES Modules natively with different loading behavior.
Click to reveal answer
intermediate
Why can't browser JavaScript use Node.js built-in modules like 'http' or 'fs'?
Browser JavaScript cannot use Node.js built-in modules because browsers restrict access to system resources for security, and those modules rely on server-side capabilities not available in browsers.
Click to reveal answer
Which object represents the global scope in Node.js?
Aglobal
Bwindow
Cdocument
Dself
✗ Incorrect
Node.js uses 'global' as the global object, unlike browsers which use 'window'.
Can Node.js directly read and write files on your computer?
AOnly with browser permission
BNo, it is sandboxed like browsers
CYes, using built-in modules
DOnly with special plugins
✗ Incorrect
Node.js can access the file system directly using modules like 'fs' because it runs on the server.
Which environment runs JavaScript inside a web browser?
ANone of the above
BNode.js
CServer JavaScript
DBrowser JavaScript
✗ Incorrect
Browser JavaScript runs inside the web browser on the client side.
Why can't browser JavaScript use Node.js modules like 'http'?
ABecause Node.js modules are written in a different language
BBecause browsers do not allow direct system access
CBecause browsers do not support JavaScript
DBecause Node.js modules are deprecated
✗ Incorrect
Browsers restrict access to system resources for security, so Node.js modules that require system access cannot run in browsers.
Which module system is commonly used in Node.js?
ACommonJS
BAMD
CUMD
DNone
✗ Incorrect
Node.js commonly uses CommonJS modules, though it also supports ES Modules.
Explain three key differences between Node.js and browser JavaScript environments.
Think about where the code runs and what it can access.
You got /3 concepts.
Describe why Node.js can use modules like 'fs' and 'http' but browser JavaScript cannot.
Consider security and environment restrictions.
You got /3 concepts.
Practice
(1/5)
1. Which of the following is a key difference between Node.js and browser JavaScript?
easy
A. Browser JavaScript can run server-side code, but Node.js cannot.
B. Browser JavaScript can access databases directly, but Node.js cannot.
C. Node.js runs only inside web pages, while browser JavaScript runs on servers.
D. Node.js can access the file system, but browser JavaScript cannot.
Solution
Step 1: Understand environment capabilities
Node.js runs outside the browser and can access system resources like files.
Step 2: Compare browser limitations
Browser JavaScript runs inside web pages and cannot access the file system for security reasons.
Final Answer:
Node.js can access the file system, but browser JavaScript cannot. -> Option D
Quick Check:
File system access = Node.js only [OK]
Hint: Remember: Node.js can read files; browsers cannot [OK]
Common Mistakes:
Thinking browser JavaScript can access local files directly
Confusing server-side and client-side roles
Assuming Node.js runs inside web pages
2. Which syntax correctly imports the built-in 'fs' module in Node.js?
import fs from 'fs'; is ES module syntax, which requires special setup; var fs = fetch('fs'); and let fs = import('fs'); are invalid for module import.
Hint: Use require() to import built-in modules in Node.js [OK]
Common Mistakes:
Using browser import syntax without Node.js ES module setup
Confusing fetch() with module import
Trying to use import() as a variable assignment
3. What will the following Node.js code output?
console.log(typeof window);
medium
A. "undefined"
B. "object"
C. "function"
D. "null"
Solution
Step 1: Understand the 'window' object context
The 'window' object exists in browsers as the global object for the page.
Step 2: Check Node.js global objects
Node.js does not have a 'window' object, so it is undefined.
Final Answer:
"undefined" -> Option A
Quick Check:
window in Node.js = undefined [OK]
Hint: window is browser-only; Node.js has no window [OK]
Common Mistakes:
Assuming window exists in Node.js
Confusing global and window objects
Expecting 'object' type for window in Node.js
4. Identify the error in this Node.js code snippet:
import fs from 'fs';
const data = fs.readFileSync('file.txt', 'utf8');
console.log(data);
medium
A. The file path must be absolute, not relative.
B. readFileSync requires a callback function.
C. Using import without enabling ES modules causes a syntax error.
D. console.log cannot print file contents.
Solution
Step 1: Check import syntax in Node.js
By default, Node.js uses CommonJS; import requires ES module setup or .mjs extension.
Step 2: Validate readFileSync usage
readFileSync is synchronous and does not need a callback.
Final Answer:
Using import without enabling ES modules causes a syntax error. -> Option C
Quick Check:
import needs ES module setup in Node.js [OK]
Hint: Use require() or enable ES modules for import [OK]
Common Mistakes:
Thinking readFileSync needs a callback
Assuming relative paths always cause errors
Believing console.log can't print strings
5. You want to write a Node.js script that reads a file and sends its content to a web page. Which approach correctly uses Node.js features to do this?
hard
A. Use Node.js to read the file with 'fs', then serve it via an HTTP server module.
B. Use browser JavaScript to read the file directly and send it to the server.
C. Use Node.js to run code inside the browser to access the file system.
D. Use browser JavaScript to create an HTTP server and read files.
Solution
Step 1: Understand Node.js capabilities
Node.js can read files using 'fs' and create servers using 'http' or similar modules.
Step 2: Identify correct client-server roles
Browser JavaScript cannot read files directly from disk or create servers; Node.js handles server tasks.
Final Answer:
Use Node.js to read the file with 'fs', then serve it via an HTTP server module. -> Option A
Quick Check:
Node.js reads files and serves content [OK]
Hint: Node.js handles files and servers; browsers handle UI [OK]
Common Mistakes:
Expecting browser JS to read local files without user action