Unit 1 - Practice Quiz

INT222

1 Which JavaScript engine is Node.js built upon?

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

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

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

3 Who created Node.js?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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. require('/moduleName')
D. import moduleName

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

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

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

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

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

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

18 Which method of EventEmitter causes an event to occur?

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

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

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

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

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

21 What is 'Callback Hell'?

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

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

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

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

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

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

A. fs.addFile()
B. fs.writeAfter()
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.stringify()
C. JSON.convert()
D. JSON.toString()

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

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

28 What is a Stream in Node.js?

A. A continuous flow of data handled piece by piece
B. A database connection
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. Duplex
D. Transform

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

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

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

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

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

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

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

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

34 What are the three states of a Promise?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

43 What is a 'Duplex' stream?

A. A stream that can only read
B. A stream that can only write
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. .json
B. .js
C. .mjs
D. .ts

45 How can you install a package globally using npm?

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

46 What does 'npm' stand for?

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

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

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

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. It throws an error
D. The promise chain stops

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

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

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

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