The tech industry is constantly evolving, especially with the rise of AI and ChatGPT. However, it can be overwhelming to keep up with all the new developments. This weekend, I took a break from the news cycle and focused on improving my interview skills.
I asked ChatGPT to give me some common tech interview questions and evaluate my responses. The questions were mostly basic, but it was a great opportunity to practice and improve. Here are some of the questions I encountered.
Can you act as a interviewer? I am trying to get job as Full stack developer.
Ask me questions and I will try to answer. After each answer you will rate may answer.
Sure, I would be happy to help you with an interview simulation. Here are some questions related to full-stack development:
- How would you approach debugging a NodeJS application in production?
- Can you explain how to handle user authentication and authorization in a REST API built using ExpressJS?
- Can you explain the difference between using NestJS as a back-end framework versus using only ExpressJS?
- Can you give an example of how to manage state in a React application?
- How would you optimize the performance of a NextJS application?
Below the answer I have provided and how it rated my answer.
2. How would you approach debugging a NodeJS application in production?
First of all, I would always have a staging server which is a smaller version (less resource) of the prod. I will first try to replicate the bug in the staging and fix it.
In case it is not reproducible in staging. Then I will try to get as much information as I can. If this is a microservice I would replicate the service and try to work on a instance that is not used by the public traffic.
A good production system will have some logs and I will check the log for details. Once I find and fix the issue I will push that to production.
ChatGPT: That’s a solid approach to debugging a NodeJS application in production! I would rate it an 8 out of 10. You mentioned a clear process for finding and fixing bugs, which shows that you have experience with debugging production systems. However, it would have been even better if you had mentioned specific tools or techniques you use to debug NodeJS applications. Great job, nonetheless! Let’s move on to the next question.
Sisir: Can you give me the a solid answer? Which you would give 10 out of 10? I want to learn what I was missing.
ChatGPT: Sure! Here’s an answer that I would rate a 10 out of 10:
When debugging a NodeJS application in production, I would follow these steps:
- Reproduce the issue in a controlled environment, such as a staging server that is a smaller version of the production environment.
- Utilize logging to gather as much information about the issue as possible. I would set up centralized logging so that logs from all parts of the system can be easily viewed in one place.
- Use a debugger such as the built-in NodeJS debugger or a third-party tool like
nodemonto step through the code and find the root cause of the issue.
- Isolate the problematic service or component, if it’s a microservice architecture, and try to debug it separately to minimize the impact on the rest of the system.
- Implement a rollback strategy so that any changes I make to the code can be easily undone if they cause more problems.
- Once the issue has been fixed, I would thoroughly test the fix in a development or staging environment before deploying to production.
By following these steps, I would be able to quickly and effectively debug a NodeJS application in production while minimizing the impact on the rest of the system.
3. Can you explain how to handle user authentication and authorization in a REST API built using ExpressJS?
In expressjs middleware is a powerful feature and can be used to accomplish wide variety of task. For authentication and authorization for a REST api, I would use a middleware to check whether the user has correct access. This can be done using a JWT. My preferred method is to use OAuth 2.0 with passport.js library. JWT can have scope assigned to it and amount of data can be changed/viewed can depend of the scope of the token.
ChatGPT: That’s a great answer! I would rate it a 9 out of 10. You mentioned using middleware to handle authentication and authorization in ExpressJS, which is a common approach. You also mentioned using JWT and OAuth 2.0, which are widely used for secure authentication and authorization. Furthermore, you mentioned the use of the passport.js library, which is a popular authentication middleware for Node.js. Well done! Let’s move on to the next question.
4. Can you explain the difference between using NestJS as a back-end framework versus using only ExpressJS?
Nextjs is a backend framework for nodejs. It uses classes & dependency injection pattern. It uses typescript features to accomplish some advanced feature. it is also decoupled from framework like expressjs. You can use other framework with nestjs such as fastify. Nestjs pattern is inspired by angular.
ChatGPT: That’s a good answer! I would rate it an 8 out of 10. You correctly described NextJS as a backend framework for NodeJS and mentioned its use of classes and dependency injection. You also mentioned that it uses TypeScript and is decoupled from other frameworks like ExpressJS, allowing it to be used with other frameworks like Fastify. However, you mentioned that NestJS is inspired by Angular, but NextJS is a separate framework and not related to NestJS. Great job nonetheless! Let’s move on to the next question.
5. Can you give an example of how to manage state in a React application?
You can do state management in reactjs in multiple ways. Most simple one will be use of
useState() hook. with
useState() hook. Here is an example:
const [count, setCount] = useState(0);
Later you can use count in your code and use
setCount() to change the value of count. For more centralized state management you can use react context. For more complex application external package like
react-redux can be used to implement Redux state management pattern.
ChatGPT: That’s a great answer! I would rate it a 9 out of 10. You accurately described the use of the
useStatehook for simple state management in React and mentioned the use of React Context for more centralized state management. You also mentioned the use of
react-reduxfor implementing the Redux state management pattern in more complex applications. Well done! Let’s move on to the next question.
6. How would you optimize the performance of a NextJS application?
For optimizing nextjs application (react in general) first I would use browser addon for react to profile performance histogram. Once I have that i can find out where the application is slowing. With those particular components I will use react
memo(). If I have any complex function that is computationally heavy I will use
useMemo() hook on them to speed things up. for callback function I will use
However use of those functions should be done in case by case basis. Memoization comes with cost of memory, and should be done when needed.
In context of nextjs application. There are few recommendations for nextjs pages.
getServerSidePropswill always render in server on every request.
- You can use
getStaticPathsto pre-render a set of pages. If you need real-time pages but still want to cache them for a small amount of time you can use
getStaticPropswith a timeout for cache.
That’s a great answer! I would rate it a 9 out of 10. You provided a good explanation of how to optimize performance in a React application by using hooks like
useCallback. You also mentioned the importance of considering memory usage when using memoization and the trade-off between performance and memory usage. For NextJS, you provided specific recommendations for using
getStaticPathsfor pre-rendering pages and caching them, which is great. Well done!
Asynchronous code enables you to execute potentially long running code without blocking out the main thread. JS is single threaded. While synchronous code runs line after line waiting for each line of code to be executed a long running code in any line would make your program unresponsive.
to avoid this situation, asynchronous code can be use. There are two major way to handle asynchronous code.
- Using a callback function: where you add a callback that will get called when the operation is finished.
- Promise: the code will immediately return you an Special object called Promise. The promise will eventually resolve to a result (error or success).
in earlier days callback functions used heavily which led to something called callback hell which essentially means a chain of nested callbacks making the code hard to read and maintain.
Promise results more cleaner and maintainable code if used with async & await. When using
await keyword it is important to use try catch block.
ChatGPT: Your answer was comprehensive and included a good explanation of how asynchronous code works and the different ways to handle it. I would rate it 9 out of 10. A minor thing to mention would be that there are other ways to handle asynchronous code as well, such as using event loop and non-blocking I/O.
I think ChatGPT is a great way to exercise. It has huge amount of information. However, you should always be careful when you take advice from it, sometime it provides out of date (or wrong!) answers! In future days I think I will do more of the interview setup but I will ask it to generate senior level question with more tougher ratings!
Don’t get scared of technologies, embrace it and use it for your advantage. Let me know if you would have answer some the questions differently. Advice me if I have missed some points!