edexa interview questions mern stack developer 2024
By | 7 months ago
Round 1: Node.js Interview
1. What is CORS (Cross-Origin Resource Sharing)?
- **Answer:** CORS is a security feature that allows or restricts resources on a web server to be requested from a different domain. It's implemented via HTTP headers that define permitted domains, methods, and headers. This mechanism ensures controlled and secure cross-origin requests.
2. Explain the authentication flow. How can we securely store and send tokens?
- **Answer:** The authentication flow typically includes user credential verification and issuing an authentication token (JWT or OAuth tokens). Tokens should be securely stored using mechanisms like HttpOnly cookies to prevent client-side access, or in secure storage like the OS Keychain for mobile apps. Tokens should be sent via HTTPS to avoid eavesdropping and include proper expiration and refresh mechanisms.
3. What are some ways to optimize MongoDB?
- **Answer:** Optimizations include using indexes to speed up queries, avoiding unneeded joins through embedded documents, keeping schema design consistent, reducing document size, and regularly archiving or removing unused data.
4. How do you choose between MongoDB and PostgreSQL?
- **Answer:** MongoDB is a good choice for unstructured or semi-structured data and applications requiring flexibility and horizontal scalability. PostgreSQL excels in ACID compliance, structured data integrity, and complex queries. Choose based on data structure, scalability needs, and relational versus non-relational data use cases.
5. How does Webpack work in a React environment?
- **Answer:** Webpack is a module bundler that processes and bundles JavaScript modules and assets. In React, it handles transpiling JSX code, bundling CSS, and optimizing assets. It ensures that the entire application is bundled into a single or a few files, optimizing load times.
6. What is a Buffer in Node.js?
- **Answer:** A Buffer is a built-in global object that allows handling of binary data streams. It helps in reading or writing binary data directly, which is essential for file manipulation, networking, and data streaming.
7. How does file upload work in Node.js?
- **Answer:** File uploads are handled by middleware like `multer` or
busboy
. The middleware intercepts the request, parses the multipart form-data, and stores the files on the server. The files can be processed or saved to the filesystem or cloud storage.
8. How does authentication work in Node.js?
- **Answer:** Authentication involves verifying user credentials against a data store (e.g., database) and issuing a session identifier (cookie, JWT). Middleware like `passport.js` helps implement various strategies such as OAuth, SAML, or custom methods.
9. How can we store tokens securely in the browser?
- **Answer:** Store tokens in HttpOnly cookies to prevent access via JavaScript or use secure client-side storage like `localStorage` with encryption. Limit exposure through CSRF tokens and consider SameSite cookie policies.
10. How can we securely send tokens through APIs?
- **Answer:** Use HTTPS for all API communication. Include tokens in the `Authorization` header or HttpOnly cookies to avoid exposure through URL parameters. Implement access control and signature verification.
11. What are the performance differences between MongoDB and PostgreSQL?
- **Answer:** MongoDB typically has faster write speeds due to its schema-less nature but can struggle with complex joins. PostgreSQL excels with complex relational queries and indexing but might not be as fast for unstructured data ingestion.
12. What are the advantages of Node.js?
- **Answer:** Node.js has non-blocking I/O, enabling concurrent request handling. It uses JavaScript throughout, providing seamless frontend-backend development. With its vast ecosystem and scalability features, it's ideal for real-time applications.
13. What is the difference between a Left Join and a Right Join?
-
**Answer:** In SQL:
-
Left Join returns all records from the left table and matching records from the right table. If there's no match, NULLs are returned for the right table.
-
Right Join returns all records from the right table and matching records from the left. If there's no match, NULLs are returned for the left table.
14. Why is mutable vs immutable important in React?
- **Answer:** Immutable data ensures predictable updates, simplifies state comparison, and improves performance. React leverages immutability for efficient re-renders via "shallow" comparisons, helping with reliable UI updates.
Round 2: React Developer Interview
1. What is the longest common prefix?
- **Answer:** The longest common prefix is the longest starting substring shared among an array of strings. For instance, given
["flower", "flow", "flight"]
, the longest common prefix is"fl"
.
2. Can a string be rearranged to form a palindrome?
- **Answer:** A string can be rearranged to form a palindrome if no more than one character has an odd count. Palindromes are symmetric, requiring pairs of characters with at most a single middle character.