Unit 1: Getting Started with Node.JS & Handling Data I/O in Node.js - Practice Quiz

INT222 — Advanced Web Development 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which JavaScript engine is Node.js built upon?

A. Chakra
B. SpiderMonkey
C. V8
D. JavaScriptCore

2 Which of the following best describes the nature of Node.js?

A. Single-threaded and non-blocking
B. Multi-threaded and non-blocking
C. Multi-threaded and blocking
D. Single-threaded and blocking

3 Who created Node.js?

A. Brendan Eich
B. Tim Berners-Lee
C. Jordan Walke
D. Ryan Dahl

4 What does REPL stand for in the context of Node.js?

A. Run Execute Print Loop
B. Read Execute Process List
C. Read Evaluate Process Loop
D. Read Eval Print Loop

5 Which command allows you to enter the Node.js REPL environment in a terminal?

A. repl
B. js
C. node
D. npm start

6 In the Node.js REPL, what does the underscore variable (_) represent?

A. The current directory
B. An undefined variable
C. The last evaluated result
D. The global scope

7 Which command is used to initialize a new Node.js project and create a package.json file?

A. npm init
B. npm new
C. npm install
D. npm start

8 Which flag can be used with 'npm init' to skip the questionnaire and use default values?

A. -y
B. --default
C. --skip
D. -f

9 Where does npm install the dependencies for a local project by default?

A. /usr/local/lib
B. global_modules
C. npm_packages
D. node_modules

10 Which file stores the metadata and dependency list for a Node.js project?

A. node_modules
B. package.json
C. config.xml
D. index.js

11 Which function is used to include modules in Node.js?

A. include()
B. fetch()
C. import()
D. require()

12 Which of the following is a Core Module in Node.js?

A. mongoose
B. fs
C. express
D. lodash

13 How do you export a function or object from a module in Node.js using CommonJS?

A. export default
B. module.exports
C. exports.module
D. return module

14 Which syntax is correct to import a local module located in the same directory?

A. require('/moduleName')
B. require('moduleName')
C. import moduleName
D. require('./moduleName')

15 What is the purpose of the 'events' module in Node.js?

A. To handle and trigger events
B. To handle file operations
C. To handle HTTP requests
D. To stream data

16 Which class is the primary component of the 'events' module?

A. EventHandler
B. EventDispatcher
C. EventListener
D. EventEmitter

17 Which method of EventEmitter is used to register a listener for an event?

A. listen()
B. emit()
C. on()
D. trigger()

18 Which method of EventEmitter causes an event to occur?

A. fire()
B. emit()
C. dispatch()
D. call()

19 What is a 'callback' in Node.js?

A. A function passed as an argument to be executed later
B. A global variable
C. A blocking function
D. A recursive loop

20 What is the convention for the first argument of a Node.js callback function?

A. The error object (or null)
B. The configuration object
C. The callback function itself
D. The result data

21 What is 'Callback Hell'?

A. A syntax error in callbacks
B. A security vulnerability
C. Deeply nested callbacks making code hard to read
D. When a callback never executes

22 Which method is used to read a file asynchronously in Node.js?

A. fs.read()
B. fs.readFile()
C. fs.readFileSync()
D. fs.open()

23 What happens if you use 'fs.writeFile()' on an existing file?

A. It throws an error
B. It creates a backup copy
C. It replaces the file content
D. It appends data to the end

24 Which 'fs' method is used to add data to a file without overwriting it?

A. fs.writeAfter()
B. fs.addFile()
C. fs.appendFile()
D. fs.insert()

25 How do you delete a file using the 'fs' module?

A. fs.delete()
B. fs.remove()
C. fs.unlink()
D. fs.erase()

26 Which method converts a JavaScript object into a JSON string?

A. JSON.parse()
B. JSON.toString()
C. JSON.convert()
D. JSON.stringify()

27 Which method parses a JSON string into a JavaScript object?

A. JSON.stringify()
B. JSON.objectify()
C. JSON.decode()
D. JSON.parse()

28 What is a Stream in Node.js?

A. A database connection
B. A continuous flow of data handled piece by piece
C. A large file stored in memory
D. A static HTML page

29 Which type of stream can generally be used to read data from a source?

A. Writable
B. Readable
C. Transform
D. Duplex

30 What is the purpose of the 'pipe()' method in streams?

A. To connect a readable stream to a writable stream
B. To delete the stream
C. To pause the stream
D. To convert stream to buffer

31 Which module allows you to work with file paths specifically?

A. url
B. http
C. fs
D. path

32 Which Node.js module provides compression and decompression functionality?

A. zip
B. crypto
C. zlib
D. compress

33 Which function creates a stream that compresses data using Gzip?

A. zlib.createGzip()
B. zlib.zip()
C. zlib.gzip()
D. zlib.compress()

34 What are the three states of a Promise?

A. Start, Stop, Pause
B. True, False, Null
C. Running, Waiting, Dead
D. Pending, Fulfilled, Rejected

35 Which method is used to handle the successful resolution of a Promise?

A. .finally()
B. .catch()
C. .then()
D. .done()

36 Which method is used to catch errors in a Promise chain?

A. .then()
B. .catch()
C. .fail()
D. .error()

37 What does the 'async' keyword do when placed before a function?

A. It ensures the function returns a Promise
B. It makes the function synchronous
C. It pauses the event loop
D. It makes the function run in a separate thread

38 The 'await' keyword can only be used inside which type of function?

A. Callback functions
B. Any function
C. async functions
D. Synchronous functions

39 What is the benefit of using async/await over callbacks?

A. It bypasses the V8 engine
B. It creates multi-threading
C. It runs faster
D. It writes asynchronous code that looks synchronous and is easier to read

40 What is the global object in Node.js equivalent to 'window' in browsers?

A. global
B. root
C. document
D. process

41 Which global variable holds the directory name of the current module?

A. process.cwd()
B. module.path
C. __filename
D. __dirname

42 Which method checks if a file exists in Node.js (Modern approach)?

A. fs.validate()
B. fs.check()
C. fs.exists()
D. fs.access()

43 What is a 'Duplex' stream?

A. A stream that can only write
B. A stream that can only read
C. A stream that can both read and write
D. A stream that compresses data

44 What is the file extension typically used for a file containing CommonJS module code?

A. .js
B. .ts
C. .mjs
D. .json

45 How can you install a package globally using npm?

A. npm add package global
B. npm install package --all
C. npm global install package
D. npm install package -g

46 What does 'npm' stand for?

A. New Package Module
B. Node Process Manager
C. Node Project Manager
D. Node Package Manager

47 When using 'fs.createReadStream', which event is fired when the file is completely read?

A. finish
B. close
C. end
D. done

48 In a Promise, what happens if you return a value in a .then() block?

A. The value is ignored
B. The next .then() receives it as a resolved value
C. The promise chain stops
D. It throws an error

49 What is the main advantage of Streams over reading files into memory?

A. Streams sort data automatically
B. Streams use less memory (memory efficiency)
C. Streams are synchronous
D. Streams encrypt data automatically

50 Which core module allows you to create a web server?

A. fs
B. http
C. net
D. url