




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The JSNAD Exam, developed by the OpenJS Foundation, certifies Node.js developers in designing, building, and deploying production-ready applications. Topics include asynchronous programming, event-driven architecture, Node core APIs, security, testing, and package management. The performance-based test is hands-on, ensuring certified developers are capable of writing efficient, scalable server-side JavaScript applications.
Typology: Exams
1 / 119
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. What is the primary purpose of Node.js's event loop? A) To execute JavaScript code sequentially B) To manage concurrency and handle asynchronous operations C) To compile JavaScript into machine code D) To manage the DOM in server-side rendering Answer: B Explanation: The event loop in Node.js manages non-blocking asynchronous operations by handling callbacks, thus enabling concurrency without multi- threading. Question 2. Which core Node.js module is used to create an HTTP server? A) fs B) http C) net D) url Answer: B Explanation: The 'http' module allows Node.js to create server instances that listen for and respond to HTTP requests.
Question 3. How do you handle errors in Node.js callback functions? A) Using try-catch blocks B) By passing an error object as the first argument C) Using Promise.catch() D) By catching exceptions with process.on('error') Answer: B Explanation: Node.js uses error-first callbacks where the first argument is an error object. If an error occurs, it is passed as this argument; otherwise, it is null or undefined. Question 4. Which method converts a callback-based function into a Promise-based one? A) util.promisify() B) Promise.all() C) async() D) callbackify() Answer: A Explanation: 'util.promisify()' wraps callback-based functions to return Promises, enabling use with async/await syntax.
Question 7. How do you globally install a package using npm? A) npm install [package] B) npm install - g [package] C) npm create [package] D) npm run [package] Answer: B Explanation: The '-g' flag installs the package globally, making it accessible from anywhere on the system. Question 8. In npm, what is the purpose of the 'package.json' file? A) To list project dependencies and scripts B) To define environment variables C) To compile the project D) To store build artifacts Answer: A Explanation: 'package.json' manages project metadata, dependencies, scripts, and configurations needed for npm packages.
Question 9. Which framework is most commonly used for building web applications in Node.js? A) Angular B) React C) Express.js D) Vue.js Answer: C Explanation: Express.js is a minimal and flexible Node.js framework for building web applications and APIs. Question 10. How do you define a route handler for GET requests in Express? A) app.get('/route', handlerFunction) B) app.post('/route', handlerFunction) C) app.route('/route').get(handlerFunction) D) Both A and C Answer: D Explanation: Both 'app.get()' and 'app.route().get()' define handlers for GET requests; the former is more direct, the latter is chainable.
Question 13. How can you handle errors in asynchronous Express route handlers? A) Using try-catch blocks inside async functions B) Passing errors to next() C) Using error-handling middleware D) All of the above Answer: D Explanation: All methods are valid; try-catch handles errors inside async functions, passing to 'next()' delegates error handling, and middleware can catch errors globally. Question 14. Which package is commonly used for environment variable management in Node.js? A) dotenv B) config C) env-cmd D) All of the above Answer: D
Explanation: All listed packages help manage environment variables; 'dotenv' is the most popular for loading variables from a '.env' file. Question 15. What is the purpose of the 'winston' library? A) Logging application data and errors B) Managing HTTP requests C) Handling database connections D) Parsing request bodies Answer: A Explanation: 'winston' is a versatile logging library for Node.js, enabling logging of application activity, errors, and diagnostics. Question 16. Which database library is used to connect Node.js to a MySQL database? A) pg B) mongoose C) mysql D) sequelize Answer: C
Answer: A Explanation: 'mongoose.connect()' establishes a connection to a MongoDB database. Question 19. How do you define a schema in Mongoose? A) const schema = new mongoose.Schema({ ... }) B) const schema = mongoose.define({ ... }) C) const schema = new Schema({ ... }) D) Both A and C Answer: D Explanation: Both approaches are valid; 'new mongoose.Schema()' and 'mongoose.Schema()' are used to define schemas. Question 20. What is the primary purpose of Helmet middleware in Node.js applications? A) To secure HTTP headers and prevent vulnerabilities B) To parse request bodies C) To handle routing D) To log requests
Answer: A Explanation: Helmet helps secure Express apps by setting various HTTP headers to protect against well-known web vulnerabilities. Question 21. Which authentication method involves sending a token that verifies user identity? A) Basic Authentication B) OAuth C) JWT (JSON Web Token) D) Session-based authentication Answer: C Explanation: JWTs are tokens used for stateless authentication, carrying user claims securely between client and server. Question 22. How does bcrypt enhance security in handling user passwords? A) It hashes passwords with salt for secure storage B) It encrypts passwords with symmetric encryption C) It compresses passwords to save space D) It validates passwords against a database
D) Both A and B Answer: D Explanation: 'mocha test/' runs tests in the 'test' directory; 'npm test' can be configured to run Mocha scripts. Question 25. Which debugging tool is integrated into Visual Studio Code for Node.js? A) Chrome DevTools B) Node.js Inspector C) VSCode Debugger D) All of the above Answer: D Explanation: VSCode's debugger supports Node.js debugging, including integration with Chrome DevTools. Question 26. What is the purpose of Docker in deploying Node.js applications? A) To containerize applications for consistency across environments B) To compile Node.js code into native binaries
C) To replace cloud hosting providers D) To run Node.js applications without installing dependencies Answer: A Explanation: Docker containers package applications and their dependencies, ensuring consistency across development, testing, and production. Question 27. How do you specify the base image in a Dockerfile for a Node.js application? A) FROM node B) BASE node C) IMAGE node D) CONTAINER node Answer: A Explanation: The 'FROM' instruction in Dockerfile specifies the base image, commonly 'node' for Node.js apps. Question 28. Which command builds a Docker image from a Dockerfile? A) docker run B) docker build
C) To manage database migrations D) To serve static files Answer: A Explanation: CI/CD pipelines automate building, testing, and deploying code, ensuring rapid and reliable releases. Question 31. What are streams in Node.js primarily used for? A) To handle continuous data flow efficiently B) To manage user sessions C) To handle HTTP request routing D) To process database transactions Answer: A Explanation: Streams enable efficient processing of large data by reading or writing data in chunks, reducing memory usage. Question 32. Which type of stream is used for reading data? A) Writable stream B) Readable stream C) Duplex stream
D) Transform stream Answer: B Explanation: Readable streams are used to read data from a source, such as files or network sockets. Question 33. What is the purpose of the Node.js cluster module? A) To enable multi-core processing by creating worker processes B) To manage HTTP sessions C) To handle database connections D) To stream data between processes Answer: A Explanation: The 'cluster' module allows Node.js to spawn multiple worker processes to utilize multiple CPU cores. Question 34. How does 'worker_threads' differ from 'child_process' in Node.js? A) Worker threads share memory, child processes do not B) Worker threads run in separate processes C) Child processes can share memory
D) npm refresh Answer: A Explanation: 'npm update' updates all dependencies to their latest versions based on version constraints. Question 37. How can you uninstall a package globally with npm? A) npm uninstall [package] B) npm remove [package] C) npm uninstall - g [package] D) npm delete [package] Answer: C Explanation: The '-g' flag in 'npm uninstall - g' removes a globally installed package. Question 38. Which property in 'package.json' defines scripts that can be run with npm? A) dependencies B) scripts C) main
D) engine Answer: B Explanation: The 'scripts' property defines command scripts that can be executed with 'npm run'. Question 39. Which Express middleware is used to serve static files? A) express.static() B) express.serve() C) express.staticFiles() D) express.staticServer() Answer: A Explanation: 'express.static()' middleware serves static assets like images, CSS, and JavaScript files. Question 40. How do you define a parameterized route in Express? A) app.get('/user/:id', handler) B) app.get('/user/', handler) C) app.route('/user').param('id') D) Both A and C