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. JavaScriptCore
B. V8
C. SpiderMonkey
D. Chakra

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

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

3 Who created Node.js?

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

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

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

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

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

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 start
B. npm new
C. npm init
D. npm install

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

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

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

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

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

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

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

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

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

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

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

A. return module
B. export default
C. module.exports
D. exports.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 file operations
B. To handle and trigger events
C. To stream data
D. To handle HTTP requests

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

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

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

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

18 Which method of EventEmitter causes an event to occur?

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

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 result data
B. The error object (or null)
C. The configuration object
D. The callback function itself

21 What is 'Callback Hell'?

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

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

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

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

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

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

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

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

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

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

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

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

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

28 What is a Stream in Node.js?

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

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

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

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 convert stream to buffer
D. To pause the stream

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. crypto
B. compress
C. zlib
D. zip

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

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

34 What are the three states of a Promise?

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

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

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

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

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

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 makes the function run in a separate thread
D. It pauses the event loop

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

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

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

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

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

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

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

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

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

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

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. .ts
B. .mjs
C. .json
D. .js

45 How can you install a package globally using npm?

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

46 What does 'npm' stand for?

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

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

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

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

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

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

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

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

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