└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Common Express JS Interview Questions~! 2 | 3 | 4 | ### Q1: What is Express.js, and why do you use it? 5 | 6 | - Express.js is a web application framework for Node.js. It is an open-source platform for building server-side applications in JavaScript. It provides excellent features and tools to developers to develop web applications efficiently. Express.js helps developers to create and manage their applications and offers a wide range of customization options. 7 | 8 | ### Q2: How does Express.js handle routing? 9 | 10 | - Express.js has a simple routing system that allows developers to define and manage application routes. Routes can be determined using the `app.get()` and `app.post()` methods. It can be associated with callback functions executed when a request is made to the route. 11 | 12 | ### Q3: How does Express.js handle middleware? 13 | 14 | - Express.js has a middleware system that allows developers to define and manage middleware functions. These functions can perform tasks such as authentication, validation, or modification of request and response objects. Middleware functions are executed in the order they are defined. They can be added to the application using the `app.use()` method. 15 | 16 | ### Q4: How does Express.js handle request and response objects? 17 | 18 | - Express.js employs a request and response object system, granting access to information about incoming requests and outgoing responses. The request object contains details about the incoming request, including the URL, method, and headers. On the other hand, the response object is utilized to send a response back to the client. Developers use methods like `res.send()`, `res.json()`, and `res.render()` to transmit responses to the client. 19 | 20 | | Feature | Express.js | Node.js | 21 | |-----------------|-----------------------------|-----------------------------| 22 | | **Type** | Framework | Runtime environment | 23 | | **Language** | JavaScript | JavaScript | 24 | | **Purpose** | To build web applications | To run JavaScript code outside of a browser | 25 | | **Features** | Routing, middleware, template engines, etc. | Event-driven, non-blocking I/O, etc. | 26 | | **Dependencies**| Node.js | N/A | 27 | | **Popularity** | Very popular | Very popular | 28 | | **Examples** | GitHub, Uber, Netflix | PayPal, LinkedIn, Walmart | 29 | 30 | 31 | 32 | 33 | 34 | ### Q6: What is the difference between a traditional server and an Express.js server? 35 | 36 | - A traditional server is standalone, built and managed independently. Express.js server is built using the Express.js framework, running on top of Node.js. It simplifies web application creation and management, offering features for routing, middleware, and request/response handling. 37 | 38 | ### Q7: How does Express.js handle error handling? 39 | 40 | - Express.js provides an error-handling system, allowing developers to define and manage error-handling middleware functions. These functions catch and handle errors in the application and can be added using the `app.use()` method. 41 | 42 | ### Q8: What is a template engine, and how does Express.js use it? 43 | 44 | - A template engine generates HTML or other output based on dynamic data. Express.js supports engines like EJS and Handlebars, dynamically rendering HTML pages based on stored application data. 45 | 46 | ### Q9: How does Express.js handle file uploads? 47 | 48 | - Express.js supports file uploads through middleware functions and the request object. Middleware like multer or busboy can be used to handle file uploads, with access to uploaded files through the request object. 49 | 50 | ### Q10: Mention some databases with which Express JS is integrated. 51 | 52 | - Express.js is integrated with databases such as MySQL, MongoDB, PostgreSQL, SQLite, and Oracle. 53 | 54 | ### Q11: How does Express.js differ from other Node.js frameworks? 55 | 56 | - Express.js is a flexible framework with essential features for web development. Unlike other frameworks like Meteor, Sails.js, and Koa.js, which offer more features but may be unnecessary for smaller projects. 57 | 58 | ### Q12: How do you handle errors in Express.js? 59 | 60 | - Express.js handles errors using a built-in mechanism, utilizing the `next()` function. Errors can be passed to the next middleware or route handler, and an error-handling middleware can be added for execution when errors occur. 61 | 62 | ### Q13: What are middleware functions in Express.js? 63 | 64 | - Middleware functions in Express.js access and modify request and response objects. They add functionality, such as logging, authentication, and error handling, to an application. 65 | 66 | ### Q14: What is a callback function in Express.js? 67 | 68 | - A callback function in Express.js is called after a specific action, such as handling a successful or failed database query. 69 | 70 | ### Q15: What is the difference between res.send() and res.json() in Express.js? 71 | 72 | - `res.send()` sends a response with any data type, while `res.json()` sends a JSON response, setting the Content-Type header to application/JSON. 73 | 74 | ### Q16: What is the use of app.use() in Express.js? 75 | 76 | - `app.use()` adds middleware functions to an Express application, whether globally or for specific routes. 77 | 78 | ### Q17: What is the purpose of the next() function in Express.js? 79 | 80 | - The `next()` function passes control from one middleware function to the next, executing the next function in the chain. 81 | 82 | ### Q18: What is the difference between app.route() and app.use() in Express.js? 83 | 84 | - `app.route()` defines multiple route handlers for a single route, while `app.use()` adds middleware functions to an application. 85 | 86 | ### Q19: What is the purpose of the req.params object in Express.js? 87 | 88 | - `req.params` accesses route parameters in Express.js, capturing values from the URL and passing them to the request handler. 89 | 90 | ### Q20: What is the difference between req.query and req.params in Express.js? 91 | 92 | - `req.query` accesses query parameters in a URL, while `req.params` accesses route parameters. 93 | 94 | ### Q21: What is the purpose of the app.locals object in Express.js? 95 | 96 | - The `app.locals` object stores application-level data in Express.js, making it available to all templates and routes. 97 | 98 | ## Feedback 99 | 100 | If you have any feedback, please reach out to us at ashrafuj.jaman.tanbin@gmail.com 101 | 102 | 103 | ## 🔗 Links 104 | [![portfolio](https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ashrafuj-jaman-s-porfolio.vercel.app/) 105 | [![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/ashrafuj-jaman) 106 | 107 | 108 | ![Logo](https://files.catbox.moe/ttaz60.png) 109 | 110 | --------------------------------------------------------------------------------