Mern Full Stack Developer
90+ Mern Full Stack Developer Interview Questions and Answers
Q1. What is the way to save large files (e.g. photos) into MongoDB database.
Use GridFS to save large files in MongoDB database.
GridFS is a specification for storing and retrieving large files in MongoDB.
It divides the file into smaller chunks and stores them as separate documents.
GridFS provides a way to query and retrieve the file in chunks or as a whole.
To save a large file, use the GridFS API provided by the MongoDB driver.
Example: db.fs.files.insert({filename: 'photo.jpg', contentType: 'image/jpeg'})
Q2. What is the request, response and next parameter in express function?
Request, response and next are parameters in Express function for handling HTTP requests and responses.
Request object represents the HTTP request and contains properties for the request query string, parameters, body, HTTP headers, etc.
Response object represents the HTTP response that an Express app sends when it receives an HTTP request.
Next function is a middleware function that passes control to the next middleware function in the stack.
Request, response and next are commo...read more
Mern Full Stack Developer Interview Questions and Answers for Freshers
Q3. Write a program to count the number of vowels in a string.
Program to count the number of vowels in a string.
Loop through each character in the string and check if it is a vowel.
Use a counter to keep track of the number of vowels found.
Consider both uppercase and lowercase vowels.
Q4. What is the difference between microservice and monolithic architecture?
Microservices are small, independent services that communicate with each other, while monolithic architecture is a single, unified system.
Microservices are loosely coupled and can be developed and deployed independently
Monolithic architecture is tightly coupled and requires the entire system to be deployed together
Microservices allow for better scalability and fault tolerance
Monolithic architecture is simpler to develop and test
Examples of microservices include Netflix, Amazo...read more
Q5. Have you worked on any file upload tasks previously ? Explain the process and how it saved in DB and retrieval process
Yes, I have experience with file upload tasks. Files are saved in DB by storing the file path and retrieval is done by fetching the file path from the DB.
Used multer middleware in Node.js to handle file uploads
Saved file path in MongoDB using Mongoose schema
Retrieved file by querying the database for the file path
Implemented file upload functionality in a project using React for the front end
Q6. Can you outline a simple strategy for fallback error handling in a Node.js application using async/await?
Use try-catch blocks to handle errors in async/await functions in Node.js applications.
Wrap the async function in a try block and catch any errors using a catch block.
Use the throw keyword to throw custom errors within the async function.
Handle promise rejections using the catch block of the async/await function.
Use the finally block to execute cleanup code regardless of whether an error occurred or not.
Share interview questions and help millions of jobseekers 🌟
Q7. Create a react table with a button and when clicked, route to another page, trigger an API, and display the data in tabular format using react.js .
Create a react table with a button to route to another page, trigger an API, and display data in tabular format.
Create a React component for the table
Add a button to the table rows
Implement routing using React Router
Handle button click event to navigate to another page
On the new page, trigger an API call using Axios or Fetch
Retrieve the data from the API response
Display the data in tabular format using HTML table or a UI library like Material-UI
Q8. What is react how it is different from html and angular
React is a JavaScript library for building user interfaces, while HTML is a markup language and Angular is a framework.
React is a JavaScript library for building interactive user interfaces.
HTML is a markup language used for structuring content on web pages.
Angular is a full-fledged framework for building web applications.
React uses a virtual DOM for efficient rendering, while Angular uses two-way data binding.
React components are reusable and composable, making it easier to ...read more
Mern Full Stack Developer Jobs
Q9. Node is single threaded then how to achieve asynchronous behaviour of it?
Node.js achieves asynchronous behavior through event-driven architecture and non-blocking I/O operations.
Node.js uses event-driven architecture to handle asynchronous operations.
It utilizes non-blocking I/O operations to allow multiple operations to be executed concurrently.
Node.js uses callbacks, promises, and async/await to manage asynchronous code execution.
Example: Using callbacks in Node.js to handle asynchronous file operations.
Q10. 1.Find next greater element for each element in the given array of integers
Use stack to find next greater element for each element in the array
Create an empty stack to store indices of elements
Iterate through the array and for each element, pop elements from stack until finding a greater element
Store the next greater element in a result array
Q11. Find the last non repetitive charter from an string "Hello"
Find the last non-repetitive character in a given string
Iterate through the string from right to left
Check if the character is not repeated before it
Return the first non-repeated character found
Q12. 2.In an array, find triplets such that their sum is 0.
Use three pointers to find triplets with sum 0 in an array.
Sort the array first to easily find triplets.
Use three pointers - one fixed, one moving from left, one moving from right.
Check if the sum of the three pointers is 0, if not adjust pointers accordingly.
Q13. What are synchronous and asynchronous functions?
Synchronous functions execute one task at a time, while asynchronous functions can execute multiple tasks simultaneously.
Synchronous functions block the execution of code until the task is completed.
Asynchronous functions allow the code to continue executing while the task is being completed in the background.
Callbacks, promises, and async/await are common ways to handle asynchronous functions.
Synchronous functions are easier to read and debug, while asynchronous functions ar...read more
Q14. new es6 features, difference between regular and arrow functions, difference between promises and async/await, implementation of time-complexity in javascript context, et.
ES6 features, arrow functions, promises vs async/await, time complexity in JavaScript.
ES6 features include arrow functions, template literals, destructuring, spread/rest operators, etc.
Arrow functions have a more concise syntax and do not bind their own 'this' value.
Promises are objects representing the eventual completion or failure of an asynchronous operation.
Async/await is a syntactic sugar for working with promises, making asynchronous code look synchronous.
Time complexi...read more
Q15. Why $lookup , $project , ..ect are used ?
They are used in MongoDB aggregation pipeline to perform various operations like joining, filtering, projecting, etc.
Used in MongoDB aggregation pipeline for data manipulation
Perform operations like joining, filtering, projecting, etc.
Help in combining data from multiple collections
Use $lookup to perform a left outer join between two collections
Q16. what is differnce between class and functional component
Class components are ES6 classes that extend from React.Component and have a render method, while functional components are simple functions that return JSX.
Class components are more feature-rich and have access to lifecycle methods like componentDidMount, componentDidUpdate, etc.
Functional components are simpler and easier to read, especially for simple UI components.
Functional components can use React Hooks to manage state and side effects, while class components use this.s...read more
Q17. write a program to find sum and average of the digits that appear in the string, ignoring all other characters. string="PYnative29@#8496"
Program to find sum and average of digits in a string, ignoring other characters.
Iterate through each character in the string and check if it is a digit.
If it is a digit, convert it to an integer and add it to the sum.
Keep track of the count of digits to calculate the average at the end.
Q18. Can write code for authentication using JWT
Yes, I can write code for authentication using JWT.
Generate a JWT token upon successful login
Verify the JWT token on subsequent requests
Set expiration time for JWT tokens to enhance security
Q19. What are react hooks and explain with a usecase
React hooks are functions that let you use state and other React features in functional components.
Allow functional components to have state and lifecycle methods
Replace class components with simpler functional components
Examples: useState, useEffect, useContext
Q20. Primary key vs Foreign Key vs Unique key difference
Primary key uniquely identifies each record in a table, foreign key establishes a link between two tables, unique key ensures uniqueness of values in a column.
Primary key: uniquely identifies each record in a table, must be unique and not null.
Foreign key: establishes a link between two tables, ensures referential integrity.
Unique key: ensures uniqueness of values in a column, allows null values but only one null per column.
Q21. what is OOPS Conceps ?
OOPS (Object-Oriented Programming) concepts are the principles that define the foundation of object-oriented programming languages.
Encapsulation: Bundling data and methods that operate on the data into a single unit (object).
Inheritance: Allowing a class (subclass) to inherit properties and behavior from another class (superclass).
Polymorphism: The ability of different classes to be treated as instances of a common superclass.
Abstraction: Hiding the complex implementation det...read more
Q22. What is diffence between spread and rest operator
Spread operator is used to unpack elements from an array, while rest operator is used to gather elements into an array.
Spread operator is denoted by three dots (...) and can be used to spread the elements of an array into individual arguments.
Rest operator is also denoted by three dots (...) and can be used to gather multiple elements into an array.
Spread operator can be used in function calls, array literals, and object literals.
Rest operator is commonly used in function par...read more
Q23. Write a code to increment counter using redux store
Increment counter using Redux store in Mern Full Stack Developer interview
Create a Redux action to increment the counter
Define a Redux reducer to handle the action and update the state
Connect the component to the Redux store and dispatch the action
Q24. What are hooks in react and how to use
Hooks in React are functions that let you use state and other React features without writing a class.
Hooks were introduced in React 16.8 to allow functional components to have state and lifecycle methods.
useState() is a hook that allows you to add state to functional components.
useEffect() is a hook that allows you to perform side effects in functional components.
Custom hooks are reusable functions that can contain logic and stateful logic for components.
Q25. What is virtual DOM and how it works
Virtual DOM is a lightweight copy of the actual DOM that updates only the necessary changes to improve performance.
Virtual DOM is a concept used in React to improve performance.
It is a lightweight copy of the actual DOM.
It updates only the necessary changes instead of updating the entire DOM.
It compares the previous and current states of the DOM and updates only the changes.
It reduces the number of direct manipulations to the actual DOM, which improves performance.
Q26. which one you choose mongo vs mysql and why
I would choose MongoDB for its flexibility and scalability in handling unstructured data.
MongoDB is a NoSQL database, making it easier to work with unstructured data compared to MySQL which is a relational database.
MongoDB is highly scalable and can handle large amounts of data and high traffic loads.
MongoDB is a good choice for applications that require frequent updates and real-time analytics.
MySQL is a better choice for applications that require complex queries and transac...read more
Q27. Create a todo app with react and basic form validation
Create a todo app with react and basic form validation
Use React to create components for adding, displaying, and deleting todos
Implement basic form validation using state and event handlers
Utilize CSS for styling the app and make it user-friendly
Q28. Share your experience / task you worked on Node js
Developed a real-time chat application using Node.js with Socket.io for instant messaging functionality.
Implemented server-side logic using Node.js to handle incoming messages and broadcast them to all connected clients
Utilized Socket.io library to establish WebSocket connections for real-time communication
Integrated with MongoDB to store chat messages and user information
Implemented authentication and authorization mechanisms to ensure secure messaging
Q29. Flatter the Array [1,2,3,[4,5[6,7]]]
Flatten the nested array to a single level array
Use recursion to flatten the array
Check if each element is an array, if so, flatten it as well
Concatenate the flattened arrays to get a single level array
Q30. what are core module in node.js
Core modules in Node.js are built-in modules that provide essential functionality for Node.js applications.
Core modules are included with Node.js installation and do not require installation via npm
Some examples of core modules include fs (file system), http (http server), path (file path utilities)
Core modules can be accessed using the require() function
Q31. How aggregation works on mongodb
Aggregation in MongoDB is a framework for performing data processing operations on documents within a collection.
Aggregation pipeline stages allow for data transformation, filtering, sorting, grouping, and more
Operators like $match, $group, $project, $sort, $limit, $skip are commonly used in aggregation
Aggregation results can be output to a new collection, returned inline, or used for further processing
Q32. What is Event Loop in Node js
Event Loop in Node.js is a mechanism that allows Node.js to perform non-blocking I/O operations by offloading tasks to the operating system.
Event Loop is a single-threaded mechanism that handles asynchronous operations in Node.js.
It allows Node.js to perform I/O operations without blocking the execution of other code.
Event Loop continuously checks the event queue for new events and executes them in a loop.
Example: setTimeout() function in Node.js uses Event Loop to schedule t...read more
Q33. Why is Node js Single threaded
Node.js is single threaded to optimize performance by avoiding the overhead of managing multiple threads.
Node.js uses an event-driven, non-blocking I/O model which allows it to handle multiple requests efficiently on a single thread.
This design choice helps in avoiding the overhead of creating and managing multiple threads, leading to better performance.
Node.js leverages the underlying libuv library to handle asynchronous operations, making it single threaded.
Q34. What is contex api in react js
Context API is a feature in React that allows sharing data between components without having to pass props through every level of the component tree.
Context API provides a way to pass data through the component tree without having to pass props down manually at every level.
It is useful for sharing global data such as themes, user authentication, or language preferences.
Context API consists of three main parts: Provider, Consumer, and useContext hook.
Example: createContext() c...read more
Q35. What is Redux and why its used
Redux is a predictable state container for JavaScript apps, used to manage application state in a centralized store.
Redux helps manage the state of an application in a predictable way
It allows for a single source of truth for the state of the application
Redux is commonly used with React to manage the state of components
Actions are dispatched to update the state in Redux store
Reducers specify how the state changes in response to actions
Q36. develop application Based on mern stack on call
Develop an application based on the MERN stack on call.
MERN stack includes MongoDB, Express.js, React, and Node.js.
Use MongoDB as the database to store data.
Use Express.js as the backend framework to handle HTTP requests and responses.
Use React for the frontend to create a user interface.
Use Node.js as the runtime environment for server-side JavaScript.
Ensure the application is responsive and follows best practices for security and performance.
Q37. Difference between useMemo and useCallback
useMemo is used to memoize a value, while useCallback is used to memoize a function.
useMemo is used to memoize a value and recompute it only when its dependencies change.
useCallback is used to memoize a function and recompute it only when its dependencies change.
Example: useMemo can be used to memoize the result of a costly computation, while useCallback can be used to memoize a callback function passed to a child component.
Q38. Is Node js multi threaded?
No, Node.js is single-threaded.
Node.js uses an event-driven, non-blocking I/O model which makes it single-threaded.
It utilizes the event loop to handle multiple requests efficiently.
However, Node.js can still leverage multi-core systems by spawning child processes.
Q39. What is lexical scope in js?
Lexical scope in JavaScript refers to the visibility of variables within a block of code based on where they are defined.
Variables are accessible within the block they are defined in, as well as any nested blocks.
Variables declared outside of a block are accessible within that block and any nested blocks.
Functions create their own scope, so variables defined within a function are only accessible within that function.
Q40. What is use effect use memo
useEffect and useMemo are hooks in React that allow for managing side effects and optimizing performance.
useEffect is used to perform side effects in functional components, such as fetching data or subscribing to events.
useMemo is used to memoize the result of a function, preventing unnecessary re-computations.
Both hooks are part of the React Hooks API introduced in React 16.8.
Q41. What is error handling middleware?
Error handling middleware is a function that processes errors in an Express application.
Error handling middleware is defined with four parameters: err, req, res, and next.
It is used to catch errors that occur during the execution of route handlers or other middleware functions.
It is typically defined at the end of the middleware chain with app.use() and has a signature like (err, req, res, next) => {...}.
Example: app.use((err, req, res, next) => { console.error(err); res.stat...read more
Q42. Second most occuring character in the string
Find the second most occurring character in a string.
Create a frequency map of characters in the string
Sort the characters based on their frequency
Return the second most frequent character
Q43. Give some crud operations in Mongo db
CRUD operations in MongoDB include create, read, update, and delete operations on documents in a collection.
Create: db.collection.insertOne()
Read: db.collection.find()
Update: db.collection.updateOne()
Delete: db.collection.deleteOne()
Q44. What is the data type of NaN?
NaN is a data type in JavaScript that stands for 'Not a Number'.
NaN is a special value in JavaScript that represents an unrepresentable or undefined value.
The data type of NaN is 'number', which can be checked using the 'typeof' operator.
NaN is the result of an operation that cannot produce a meaningful numeric result, such as dividing zero by zero or multiplying infinity by zero.
Q45. Write code for reading file in node js
Reading a file in Node.js involves using the 'fs' module to open and read the contents of the file.
Use the 'fs' module's 'readFile' method to read the contents of a file asynchronously.
Pass the file path and encoding as parameters to the 'readFile' method.
Handle the file contents in the callback function provided to the 'readFile' method.
Q46. Write CRUD APIs for a sample data
Creating CRUD APIs for sample data in a MERN stack application
Create a POST API to add new data
Create a GET API to retrieve all data
Create a GET API to retrieve data by ID
Create a PUT API to update data by ID
Create a DELETE API to delete data by ID
Q47. Check if 2 strings are anagrams.
Check if 2 strings are anagrams.
Convert both strings to lowercase
Remove all non-alphabetic characters
Sort the characters in both strings
Compare the sorted strings, if they are equal, they are anagrams
Q48. What is foriegn Key SQL?
Foreign key in SQL is a field in a table that is a primary key in another table, establishing a relationship between the two tables.
A foreign key constraint ensures referential integrity between two related tables.
It helps maintain consistency and avoid orphan records.
Example: In a database with tables 'orders' and 'customers', the 'customer_id' in 'orders' table can be a foreign key referencing the 'id' column in 'customers' table.
Q49. What is lookup in mongodb?
Lookup in MongoDB is used to perform a left outer join to retrieve documents from another collection.
Lookup is used to combine data from two collections based on a common field.
It is similar to a SQL join operation.
Lookup is used in aggregation pipelines to fetch related documents from another collection.
Example: db.collection.aggregate([{ $lookup: { from: 'anotherCollection', localField: 'field', foreignField: 'field', as: 'alias' } }])
Q50. redis usage in the nodejs + express
Redis is used in Node.js + Express for caching, session management, and real-time data processing.
Redis can be used for caching frequently accessed data to improve performance.
It can also be used for session management to store user session data.
Redis is commonly used for real-time data processing in applications like chat rooms or live updates.
Example: Storing user sessions in Redis to maintain login state across multiple servers.
Interview Questions of Similar Designations
Top Interview Questions for Mern Full Stack Developer Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month